I want to retrieve the script stored in JSON format and evaluate the script on other table.

pandeyved
Tera Contributor

Hi All,

I am passing this JSON Format into my flow to update the fields on RITM form:
{"sys_db_object":"sc_req_item",

"short_description":"current.variables.variable_name.display_value,-,current.cat_item.name"}

This JSON is stored in a field in a table.

Suppose item name is "test" and variable value is "abcd"

So it should update the short description on RITM like this:
abcd - test

If I will use GlideScopeEvaluator, then what table and how I should specify.

What I should do to achieve this, pls help.

3 REPLIES 3

Namrata Ghorpad
Mega Sage
Mega Sage

Hi @pandeyved ,

You need to use RITM table to update the short description of RITM and try the code like below.

 

var now_GR = new GlideRecord('sc_req_item');
now_GR.short_description =short_description ;
now_GR.insert();
//setup variables to be used by the script
var vars = {"sys_db_object":"sc_req_item","short_description":"current.variables.variable_name.display_value,-,current.cat_item.name"};

//Evaluate the script from the field
var evaluator = new GlideScopedEvaluator();
gs.info(evaluator.evaluateScript(now_GR, 'short_description ', vars));

// Now retrieve the result
evaluator.evaluateScript(gr, 'short_description', null);
gs.info(evaluator.getVariable('result'));


 

 

Please mark my answer as correct and helpful if it helps to resolve your issue.

Regards,

Namrata

Hi @Namrata Ghorpad 

Thanks for help!
I have one doubt here, pls clarify
How it will evaluate the script on ritm table, 

gs.info(evaluator.evaluateScript(now_GR, 'short_description ', vars));

As short description in JSON is separated by comma and one more character is there which is "-".

 

Hi @pandeyved ,

You can write the code like below as well.

var vars = {"sys_db_object":"sc_req_item",
"short_description":"current.variables.variable_name.display_value,-,current.cat_item.name"};
var now_GR = new GlideRecord('sc_req_item');
now_GR.short_description=vars.short_description;
now_GR.insert();

 

Please refer the below link.

https://www.servicenow.com/community/developer-forum/script-for-json-parse-action-in-flow-designer/m... 

 

Please mark my answer as correct and helpful if it helps to resolve your issue.

Regards,

Namrata