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

In the description of your question you mention it_owner and in your code you reference it_sponsor.



If it_sponsor is a reference variable referencing the user table on your item, then your code should work.



If you want to copy from a field on the requested item called it_owner you would use task.assigned_to = current.it_owner.



Are you trying to assign the task to someone who is in a reference field or a reference variable?


Hi Brad,



Thanks for your support so far! I'm trying to assign someone who is already populated on the reference table. IE they choose the person from the sys_users, workflow moves forward, and the catalog task pulls that referenced person and sets them as the assigned_to


Brad Tilton
ServiceNow Employee
ServiceNow Employee

When you say "they choose the person from the sys_users", who is making that choice and are they doing it in a field on a task or requested item or in a variable?


The person requesting is they. But the it_sponsor is referencing the sys_user table and I'm looking to have whatever value that is chosen on that variable be the requested to on the catalog task.



So the user fills out a form, and the it_sponsor is a reference field to the sys_user table.   One of the catalog tasks I have from the workflow will need it's assigned_to field be the person listed as the it sponsor. (which may or may not be the requestor,) I wouldn't mind knowing how to do it either way in case for knowledge.