Setting Assigned to on task from a referenced field on catalog item

Derek10
Tera Expert

Hello!

 

I'm trying to setup a sc task so it will assign the assigned to to a   person from a reference field. IE it_owner (which is a reference field for sys_user)

 

I   have tried the following with no luck and have referenced both :

set assigned_to in Task

and Set task.assigned_to

 

The code I am using in the sc_task is:

task.assigned_to = current.variables.it_sponsor

 

Any clue what i'm missing?

1 ACCEPTED SOLUTION

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Ok. In the case where it_sponsor is the name of the reference variable then your original code should work. Either of the following should assign the task to the person listed in the it_owner variable.



task.assigned_to = current.variables.it_owner;


task.assigned_to = current.variable_pool.it_owner;



If neither of those work, I would add some logging into your task script. Something like:


gs.log('IT Owner is: ' + current.variables.it_owner);


task.assigned_to = current.variables.it_owner;



You can then check the script log statements and see if the value is blank or maybe the wrong sysid.


View solution in original post

7 REPLIES 7

Brad Tilton
ServiceNow Employee
ServiceNow Employee

Ok. In the case where it_sponsor is the name of the reference variable then your original code should work. Either of the following should assign the task to the person listed in the it_owner variable.



task.assigned_to = current.variables.it_owner;


task.assigned_to = current.variable_pool.it_owner;



If neither of those work, I would add some logging into your task script. Something like:


gs.log('IT Owner is: ' + current.variables.it_owner);


task.assigned_to = current.variables.it_owner;



You can then check the script log statements and see if the value is blank or maybe the wrong sysid.


Thanks yet again Brad! It is working as intended.


Hi Brad


I a similar problem.


I have a catalog item called ABC Services.   This item has a variable named v_requested_for.     I want to assign this variable to task table field named 'requested_for'.  


The workflow associated with catalog item assigns assignment_group to tasks outside the script and that works fine.   Here is what I did in the workflow associated with this item.


gs.log('v_requested_for is: ' + current.variables.v_requested_for);


Option 1:   task.requested_for = current.variables.v_requested_for;
Option 2: task.requested_for = 'My Name';



The log script shows sys_id of the user selected when this catalog item is requested.   However, the field does not get assigned either using option 1 or option 2.   Any help is appreciated.