Creating Multiple RITMs from one RITM in Workflow - Trouble setting variables

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2019 08:53 PM
Working through an issue with a workflow where I have 1 RITM that has a list of access level requests in a list collector. I've assigned the list collector to a scratchpad array and I want to parse through that array to create a new RITM for each of the items in the array. Here's my runscript:
for (var i = 1; i < workflow.scratchpad.access_list.length; i++) {
gs.sleep(1000);
gs.log('Assignment Access Level ' +workflow.scratchpad.access_list[i].toString(),workflow.scratchpad.wf_name);
var ritm = new GlideRecord('sc_req_item');
ritm.newRecord();
ritm.request = current.request;
ritm.cat_item = current.cat_item;
ritm.due_date=current.due_date;
ritm.variables.role_name=current.variables.role_name;
ritm.variables.access_level = workflow.scratchpad.access_list[i];
//ritm.variables.access_level="b0d67332e4c9e40006d80e38f69704df";
ritm.setWorkflow(true);
ritm.insert();
gs.sleep(1000);
}
When the script runs, I get a log entry that reads:
Assignment Access Level b0d67332e4c9e40006d80e38f69704df
But when the new RITM is created, the access_level variable is blank. I was expecting the line:
ritm.variables.access_level = workflow.scratchpad.access_list[i].toString();
to properly set the access_level variable (a list collector) in the new RITM, but it is not.
Likewise, the line: ritm.variables.role_name = current.variables.role_name
is not properly setting the new RITM's role_name variable.
What am I missing here?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2019 11:07 PM
Variable editor is added to the form view for sc_req_item

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2019 11:13 PM
Hi
Did you check sc_item_option_mtom table to actually see if the variables are created?
Try System property glide.sc.use_sc_form_v2 set to false

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2019 11:12 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2019 11:22 PM
Try code provided by shariq. Variables will not get copied if create RITM using code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2019 11:11 PM
TLDR; read the what you can rather do section.
What are you missing? the interpretation of the usage of variables.
Where are you wrong? expecting the created from script ritms to insert and set variables ,even before the particular variables of the catalog item are accessed and attached with the RITM.
ritm.cat_item = current.cat_item; will set the field of the new request item with the sys id of the catalog item, but doesn't knows yet which variables are contained in it.
And if you understand the process of variable creation in requested item form (NOTcatalog item form), then your approach is wrong.
What you can rather do?
This is rather a long but correct approach.
First you should know create a mtom option for the requested item and then you can save the value of the list collector.
please take help from the script below. BTW usage of sleep function is literally going to degrade your instance performance. Thus,edited.
var scr=workflow.scratchpad.access_list;//for safer purpose
for (var i = 1; i < scr.length; i++) {
// gs.sleep(1000); use timer insteads
gs.log('Assignment Access Level ' +scr[i].toString(),workflow.scratchpad.wf_name);
var ritm = new GlideRecord('sc_req_item');
ritm.newRecord();
ritm.request = current.request;
ritm.cat_item = current.cat_item;
ritm.due_date=current.due_date;
//ritm.variables.role_name=current.variables.role_name;
//ritm.variables.access_level = workflow.scratchpad.access_list[i];
//ritm.variables.access_level="b0d67332e4c9e40006d80e38f69704df";
var rtm_sys=ritm.insert();
// gs.sleep(1000); refrain fro using it.
ritm.setWorkflow(true); //do you still need this? instead keep it false to stop br executions,resulting in faster performance
var itm=new GlideRecord('sc_item_option');
itm.initialize();
itm.item_option_new='sys_id_of_the list_collector_variable';
itm.value=scr[i].toString();
var gr_mtom= itm.insert();
var varsOpt= new GlideRecord('sc_item_option_mtom');
varsOpt.initialize();
varsOpt.request_item=rtm_sys;
varsOpt.sc_item_option=gr_mtom;
varsOpt.insert();
}