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

RiteshSwarnakar
Giga Guru

Hi @sath ,

 

Hopefully this is the server-side code you are looking for:

 

var sysID='9a44f0b887d765501e8dbae8dabb35fb';     // sys_id of SCTASK
var n=[];
var q=[];

var g = new GlideRecord('sc_item_variables_task');
g.addQuery('task',sysID);
g.query();
while(g.next()){
q.push(g.variable.question_text);
n.push(g.variable.name);
}


var g1 = new GlideRecord('sc_task');
g1.addQuery('sys_id',sysID);
g1.query();
if(g1.next()){
for (var i=0; i<n.length ; i++){
var c= eval("g1.variables."+n[i]+".getDisplayValue()");
gs.print(q[i]+ ":  "+c);
}
}

 

The above is a background script, but logic can be applied in any server-side code.

 

Please let me know if this helps.

 

Thanks,

Ritesh Swarnakar