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

Loudigi
Kilo Sage

When you are referring to catalog variables in script, you must use 

current.variables.variable_name

Give that a try.

Hi,

Tried that, it doesn't display in the missing variables section.  If I route the value to the "description" field on the task it shows, but I need the variables section to show up.

I see.

Why are you using a script to generate the task? Why not use the catalog tasks activity to begin with? You can run a script in the activity as well. 

find_real_file.png

The Catalog item is an application request where users select n values from a list.  When submitted the script creates a task for each application and assigns it to its support group based on the CMDB field.  There are over 200 applications so generating via script seemed the best way. (I tried putting the script in a catalog task, but that failed.)

So the script part works fine, but the variables section is missing from the tasks and I need to know how to include them in this script.