how to pass values to json object

Priti18
Tera Expert

how can I pass the incident category value dynamically in key value format

 

var inccategory = current.category.getDisplayValue();

 var result = "{'category':inccategory} // this gives me error but if I print logs then I am able to see correct value

1 ACCEPTED SOLUTION

Laszlo Balla
ServiceNow Employee
ServiceNow Employee

Remove the quotes around the curly braces:

var result = {"category":inccategory};

View solution in original post

10 REPLIES 10

Laszlo Balla
ServiceNow Employee
ServiceNow Employee

What error are you getting? I am only see the unnecessary quotes before your curly bracket, otherwise should be fine.

var inccategory = current.category.getDisplayValue();
var result = {'category':inccategory};

Saurabh Gupta
Kilo Patron
Kilo Patron

Hi,
Do like below

var inccategory = current.category.getDisplayValue();

 var result ={};
result.category=inccategory;

var strJSON=JSON.stringify(result)

gs.info(strJSON)

Thanks and Regards,

Saurabh Gupta

Priti18
Tera Expert

I tried it gives me error in flow designer

I also tried .toString, in logs i can see the correct value but in flow designer it gives below error

 

unrecognized inccategory was expecting null, nan, string

Hi,
It will not work in flow designer as current object is not available flow like this.

 

 


Thanks and Regards,

Saurabh Gupta