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

Brian Bouchard
Mega Sage

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?

23 REPLIES 23

Creating the additional RITMs is working. It just doesn't appear to me that the variables are being set correctly.

I have tried setting the role_name to a hardcoded string, and that also doesn't appear to be setting the variable correctly.

Starting to feel like I have some fundamental issue somewhere else in this process 😞

Can you share screen shot of RITM created which must include those variables also??

Ok. So, I created 1 REQ that has 1 RITM of the Catalog Item "Add Access To Role"  This RITM has a role_name and access_level list collector with 2 values:

find_real_file.png

 

 

When this goes through the workflow, I'm ultimately trying to create a second RITM that has the same role_name, but only the 2nd item in the access_level list collector.  When I look at the RITM for this second item, I can't see the variables at all:

find_real_file.png

 

I understand this alone probably doesn't mean the variables aren't being set. Maybe there's something I need to do to make the variables show up on the new RITM I'm creating?

But when I report on the variables for the RITMS, I can't see anything set for this second RITM that I've created through the run script.

Not sure if the above images were what you were looking for. If not, please let me know. I really appreciate the help with this, as I've been struggling with this for a week or more. I'm also open to doing this a different way if it makes more sense to go in that direction.  Ultimately, I want separate RITMs for each item in the access_list so they can all be approved individually, but since the items in the list aren't catalog items (they come from a custom table) I can't use an order guide to create the separate RITMs.

now check the request. it should have two item linked to it. If you are linking the newly created RITM to same catalog item then the variables of Add access to role will get copied. 

Also check form layout of RITM. Whether variable Editor is added or not.