- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 10:55 AM
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:
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,
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?)
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 11:50 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 11:00 AM
Hi
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 11:00 AM
Hello again
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!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 11:04 AM
Hi,
Have you try like this,
task.assigned_to.setDisplayValue(current.variables.YourVariableName);
Thanks,
Kunal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-06-2020 11:50 AM
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.