The CreatorCon Call for Content is officially open! Get started here.

RITM Variables not showing on Task (task generated via script)

Brian155
Mega Expert

Hi folks,

I have a catalog item that allows a user to request application access. This is the workflow I'm using:

find_real_file.png

I use this "Group Assignment" script to create the tasks based on the applications selected:

var app = new GlideRecord('cmdb_ci_appl');
app.addQuery('sys_id', 'IN', current.variables.select_applications);
app.query();
while(app.next()){
var sctask = new GlideRecord('sc_task');
sctask.initialize();
sctask.request_item = current.sys_id;
sctask.assignment_group = app.getValue('support_group');
//continue to populate other information like description, etc...
sctask.short_description = "Application Request for " +current.request.requested_for.getDisplayValue();
sctask.insert();
}

But the task it creates don't have the variables from the RITM.  One of the variables is a reference field called "Mirror User" (v_mirror_user). I've tried to add them (below sctask.short_description) using:

sctask.v_mirror_user=current.request.v_mirror_user.getDisplayValue();

sctask.v_mirror_user=current.request.v_mirror_user;

sctask.v_mirror_user=current.variables.v_mirror_user.getDisplayValue();

sctask.v_mirror_user=current.variables.v_mirror_user;

The v_mirror_user field would normally be added at the variables part of the catalog task:

find_real_file.png

But since this isn't a catalog task, I'm figuring that's why nothing happens.

I tried creating the Run Script called "scratchpad" to put these values in the scratchpad using the current variables above and calling them from the "Group Assignment" script like above and still nothing. I'm guessing the answer is somewhere else.

I've run out of limited ideas and the last 4 hours of searching haven't helped.  

Any ideas?

edit: This is the section I'm referring to.  It's on the RITM, but not on the tasks:

find_real_file.png

1 ACCEPTED SOLUTION

Brian155
Mega Expert

I ended up writing the variable to the scratchpad and it worked using this code:

var app = new GlideRecord('cmdb_ci_appl');
app.addQuery('sys_id', 'IN', current.variables.v_select_applications);
app.query();
while(app.next()){
   var sctask = new GlideRecord('sc_task');
   sctask.initialize();
   sctask.request_item = current.sys_id;
   sctask.assignment_group = app.getValue('support_group');
   //continue to populate other information like description, etc...
	sctask.short_description = "Grant Application Access for " +current.request.requested_for.getDisplayValue();
sctask.v_mirror_user = workflow.scratchpad.v_mirror_user;
	
	
   sctask.insert();
}

View solution in original post

5 REPLIES 5

Brian155
Mega Expert

I ended up writing the variable to the scratchpad and it worked using this code:

var app = new GlideRecord('cmdb_ci_appl');
app.addQuery('sys_id', 'IN', current.variables.v_select_applications);
app.query();
while(app.next()){
   var sctask = new GlideRecord('sc_task');
   sctask.initialize();
   sctask.request_item = current.sys_id;
   sctask.assignment_group = app.getValue('support_group');
   //continue to populate other information like description, etc...
	sctask.short_description = "Grant Application Access for " +current.request.requested_for.getDisplayValue();
sctask.v_mirror_user = workflow.scratchpad.v_mirror_user;
	
	
   sctask.insert();
}