Null reference check in watcher rule using painless script

In my watcher rule, i have implemented a looping for the items from the result as
"body": "{"Type":"MemoryUsage","MidThreshold":90,"MaxThreshold":98,"ServerDetails":[{{[#ctx](javascript:void(0);).payload.aggregations.allservers.buckets}}{"ServerName":"{{key}}","Datatype":"{{latest.hits.hits.0._source.DataType}}","NodeCategory":"{{latest.hits.hits.0._source.node_category}}","NodeType":"{{latest.hits.hits.0._source.node_type}}","NodeLocation":"{{latest.hits.hits.0._source.node_location}}","NodeIsActive":"{{latest.hits.hits.0._source.node_isactive}}","NodePageRange":"{{latest.hits.hits.0._source.node_pagerange}}","Value":{{latest.hits.hits.0._source.PercentUsedMemory}},"OtherInfo":"{{latest.hits.hits.0._source.Drive}}"},{{/ctx.payload.aggregations.allservers.buckets}}]}",

Few of my documents will not have the property {{latest.hits.hits.0._source.node_isactive}} and for those documents currently my json property contains empty value (NodeIsActive :""). What i need is a conditional based property addition to json. Only if the document contains the property latest.hits.hits.0._source.node_isactive, i should assign it to JSON property else the property NodeIsActive should not be available in the json.

you would need to execute a transform as part of that action, that checks for the both different isActive fields and unifies them into one field, as mustache as a templating language does not allow if-else constructs...

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.