Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to fetch variables (from variable editor) sc task to Story using UI Action

sath
Tera Expert

Hi @Ankur Bawiskar 

We have a UI Action 'Create Story' on sc tasks. When user clicks on it, a new story will be created and sc task will be closed. The new requirement is to capture the variables from sc task (part of variable editor - comes from catalog item) and copy them to story. Please assist.

1 ACCEPTED SOLUTION

@sath 

in client side also it will be difficult to determine.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

View solution in original post

10 REPLIES 10

Ankur Bawiskar
Tera Patron
Tera Patron

@sath 

so what script did you start with and where are you stuck?

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar I had the similar requirement for RITM too (when user clicks on create story UI action on ritm form), used the below script. But I don't see any table in servicenow that stores sc task variables and its values.

 

var story = new GlideRecord("rm_story");
story.initialize();
story.short_description = current.short_description;
story.insert();

var storySysid = story.sys_id;
var ritmVar = new GlideRecord('sc_item_option_mtom');
ritmVar.addQuery('request_item', current.getUniqueValue());
ritmVar.addNotNullQuery('sc_item_option.value');
ritmVar.orderBy('sc_item_option.order');
ritmVar.query();

var fields = '';
while (ritmVar.next()) {
    fields = fields + ritmVar.sc_item_option.item_option_new.question_text + ":  " + current.variable_pool[ritmVar.sc_item_option.item_option_new.name].getDisplayValue() + "\n";
}
story.u_ritm_variables = fields;
story.update();
action.setRedirectURL(story);

 

 

@sath 

update as this

var story = new GlideRecord("rm_story");
story.initialize();
story.short_description = current.short_description;
story.insert();

var storySysid = story.sys_id;

var ritmVar = new GlideRecord('sc_item_option_mtom');
ritmVar.addQuery('request_item', current.request_item); // use RITM field on sc_task to query
ritmVar.addNotNullQuery('sc_item_option.value');
ritmVar.orderBy('sc_item_option.order');
ritmVar.query();

var fields = '';
while (ritmVar.next()) {
fields = fields + ritmVar.sc_item_option.item_option_new.question_text + ": " + current.variable_pool[ritmVar.sc_item_option.item_option_new.name].getDisplayValue() + "\n";
}
story.u_ritm_variables = fields;
story.update();
action.setRedirectURL(story);

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

The above script is querying the ritm from sc task and fetch ritm variables, but I need the variables present on sc task form. We have many catalog items where some variables are visible only on sc tasks, but not on ritm.