set assigned to in catalog task from variable

TCarn
Giga Contributor

Hi,

I was wondering how to set the "Assigned To" variable in a catalog task from a reference field (sys_user). In my workflow, I currently have this:

find_real_file.png

The user is supposed to select the variable within the catalog task. When the user has selected the user and close the task, I would have expected the task on the RITM would then populated the variable under the "Assigned To" column. However, the "Assigned To" variable remains empty,

find_real_file.png

My question is how can I populate the choice from a variable within a catalog task to then populate the Assigned To field with it's choice (copy variable to assigned to?)

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

The script on the task activity in the workflow will set the assigned_to only when the task is created.  To do what you described, you'll want to create an onChange or onSubmit catalog client script that runs on catalog tasks.  Since the variable is a reference to sys_user, the same as Assigned to, the content of the script will simply be 

g_form.setValue('assigned_to', g_form.getValue('your_super_secret_variable_name'));

I have to say that this is an odd practice.  Typically, someone in the assignment group claims a task to let others in the group know they're working on it - so they just put their name in the Assigned to, or a supervisor does to assign work, but no variable is needed.  Also note that OOTB Assigned to is dependent on Assignment group, so you can only choose an Assigned to that's a member of the Assignment group.  This script will set the Assigned to regardless of group membership, so make sure that's what you want to do.

View solution in original post

4 REPLIES 4

Vikram Reddy
Giga Guru

Hi @TCarn ,

 

Create a onchange client script on that variable, make sure to mark checkbox 'run on catalog tasks'. Your script should use GlideAjax to perform database operation and set the assigned to value

When the user selects the variable value on catalog task, this script triggers and does the work

 

Thank you,

Vikram

Allen Andreas
Administrator
Administrator

Hello again @TCarn 

The script section there in the task activity is for what will be set UPON CREATION, of the task. Not for after. Without full context, this is a solution for a one-time catalog item task.

If you want to assign someone to the task AFTER it's closed, then you can create a run script activity and place that right after the task with script to assign it to that user.

var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.sys_id);
gr.OrderByDesc('sys_updated_on');
gr.setLimit(1);
gr.query();
if (gr.next()) {
gr.assigned_to = current.variables.xxxxxx;
}

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Kunal Varkhede
Tera Guru

Hi,

 

Have you try like this,

task.assigned_to.setDisplayValue(current.variables.YourVariableName);

 

Thanks,

Kunal

Brad Bowman
Kilo Patron
Kilo Patron

The script on the task activity in the workflow will set the assigned_to only when the task is created.  To do what you described, you'll want to create an onChange or onSubmit catalog client script that runs on catalog tasks.  Since the variable is a reference to sys_user, the same as Assigned to, the content of the script will simply be 

g_form.setValue('assigned_to', g_form.getValue('your_super_secret_variable_name'));

I have to say that this is an odd practice.  Typically, someone in the assignment group claims a task to let others in the group know they're working on it - so they just put their name in the Assigned to, or a supervisor does to assign work, but no variable is needed.  Also note that OOTB Assigned to is dependent on Assignment group, so you can only choose an Assigned to that's a member of the Assignment group.  This script will set the Assigned to regardless of group membership, so make sure that's what you want to do.