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 10:04 PM
Hi
Are these variables in a variable set where the backend names of variable and variable set is same? If yes please try to change them too. Because this may be the reason of conflict.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2019 10:09 PM
They are not part of a variable set.
role_name is a simple string variable and access_level is a list collector of sys ids.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2019 10:14 PM
Try code as below,
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.setWorkflow(false);
var id = ritm.insert();
var req = new GlideRecord("sc_req_item");
req.get(id);
req.variables.role_name=current.variables.role_name;
req.variables.access_level = workflow.scratchpad.access_list[i];
//ritm.variables.access_level="b0d67332e4c9e40006d80e38f69704df";
req.update();
gs.sleep(1000);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2019 10:22 PM
This doesn't appear to be working for me either.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-15-2019 10:26 PM
Have you tried?? Try once with dummy value also and check the variable on created RITM,
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.setWorkflow(false);
var id = ritm.insert();
}