- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-16-2023 06:52 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2023 07:58 PM
in client side also it will be difficult to determine.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-14-2023 07:23 AM - edited 06-14-2023 07:25 AM
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