How to use JSON object in Workflow

Aruna Sree Yela
Tera Guru

Hi,

 

There is a Record Producer, after submitting it a record will be created in Case table and there is a field called "JSON Output" which stores data of submitted RP

 

JSON body looks as below

{
    “field1”:{
        “original_value”:””,
        “changed_value:””,
        “field_display_value:””
    },

“field2”:{
        “original_value”:””,
        “changed_value:””,
        “field_display_value:””
    },
    …
}

 

Now, I wanted to use the data stored in this "JSON Output" field on Workflow. The condition looks like below

 

ArunaSreeYela_0-1708092135472.png

 

Now I wanted to know how to do below 2 things

 

1. Get JSON data from "JSON Output" field into JSON Object[Action in flow]

2.Here JSON object stores 2fields, so field1 should considered in first if block and I need to write field1!=empty, same for 2nd field.

 

How can I achieve this.

 

Guidance is appreciated.

 

Thanks

 

11 REPLIES 11

saurabh_dubey
Kilo Sage

Hi @Aruna Sree Yela ,

Please go through this article https://docs.servicenow.com/bundle/washingtondc-build-workflows/page/administer/flow-designer/concep... 

 

 

If you find my answer helpful do hit the like button and mark my answer helpful

Thanks,

Saurabh

Hi @saurabh_dubey ,

 

Thanks for the response.

 

This is for Flow Design right, I want it for Workflow.

 

So @Aruna Sree Yela ,

 

Can you share the snap of the flow or is it written in the runscript node of the workflow.

 

if yes then you should have a condition like this.

 

if you Store JSON body in result variable;

 

result = 

{
    “field1”:{
        “original_value”:””,
        “changed_value:””,
        “field_display_value:””
    },

“field2”:{
        “original_value”:””,
        “changed_value:””,
        “field_display_value:””
    },
    …
}

 

var result2 = JSON.parse(result); // parse to get the value

 

if (result.field1){

      return result2.field1;

}

else{return return result2.field2;} // if not field one

 

This should work @Aruna Sree Yela 

 

If my answer found useful do mark the helpful button,

 

Thanks,

Saurabh.

 

 

Hi @saurabh_dubey ,

 

I have not written workflow yet, as I'm not clear about how can I do it with the JSON. Can you please guide me on this. If possible please provide me the snip.

 

Thanks