- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-09-2022 11:26 PM
Hi All,
I have a requirement to take values from the task variables and insert records in a custom table.
- i.e there is a variable in the catalog task table 'transfer number' which will have comma separated values 1234567890,34567890,..
- once the task is closed need to add a run script in the workflow to create records in the custom table for each value added in the above variable. If the 'Transfer number' contains 2 values then 2 records need to be created in custom table.
- Have configured the below script but i am stuck and not able to proceed can anyone suggest the solution.
- var val = [];
var task = new GlideRecord('sc_task');
task.addQuery('request_item', current.sys_id);
task.query();
if(task.next()){
var trnVal = task.variables.trn;
val.push(trnVal);
gs.log("value of the TRN is " + trnVal);
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 07:01 AM
Hi,
it means you are using incorrect variable name
use this directly; no need to query RITM table
var trnValArr = current.variables.trn.toString().split(',');
gs.info("My values ->" + trnValArr); // what came here
for(var i in trnValArr){
gs.info("inside of for loop");
var gr = new GlideRecord('u_transfer_order');
gr.initialize();
gr.u_trn = trnValArr[i];
gr.insert();
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 02:41 AM
Hi Ankur,
Thank you. I will try the above code and update you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 03:49 AM
Hi Ankur,
I tried the above code its not working.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 03:54 AM
workflow is on which table?
can you share latest script?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 04:12 AM
Hi Ankur,
Workflow is on RITM table ('sc_req_item)
var val = [];
var task = new GlideRecord('sc_task');
task.addQuery('request_item', current.sys_id);
task.query();
if(task.next()){
var trnValArr = task.variables.trn.split(',');
for(var i in trnValArr){
gs.log("inside of for loop");
var gr = new GlideRecord('u_transfer_order');
gr.initialize();
gr.u_trn = trnValArr[i];
gr.insert();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-10-2022 04:18 AM
Hi,
so what is not working?
is it not iterating the for loop?
var val = [];
var task = new GlideRecord('sc_task');
task.addQuery('request_item', current.sys_id);
task.query();
if(task.next()){
var trnValArr = task.variables.trn.split(',');
gs.info("My values ->" + trnValArr); // what came here
for(var i in trnValArr){
gs.info("inside of for loop");
var gr = new GlideRecord('u_transfer_order');
gr.initialize();
gr.u_trn = trnValArr[i];
gr.insert();
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader