Get a first look at what's coming. The Developer Passport Australia Release Preview kicks off March 12. Dive in! 

How to get the user id of the Opened by to Created by in sctask (in workflow script)

ss123
Tera Contributor

Hi everyone,

 

I would like to check if how can I get the user id of the Opened by in SCTask to Created by field.

Here's a screenshot for reference.

SabrinaSalazar_0-1689306038835.png

 

The script i'm using in  workflow catalog task is not working:

task.sys_created_by = task.opened_by.user_id;

 

 

Thanks in advance!

12 REPLIES 12

@ss123 

are you sure you are using correct variable name for requested_by

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

yes that is correct. tho the requested by field is on a variable set (core_opened_by_for).

So I tried to do it like:

task.sys_created_by = current.variables.core_opened_by_for.requested_by.user_name;

 

But it didn't work.

@ss123 

you need not use variable set name while accessing variable value

Regards,
Ankur
Certified Technical Architect  ||  10x ServiceNow MVP  ||  ServiceNow Community Leader

@Ankur Bawiskar 

I just used BR for this concern. Now the Created by is correct.

 

Anyway, thanks for your help!

Rahul Talreja
Mega Sage

Hi @ss123 ,
Try using ,

task.sys_created_by = current.variables.requested_by;
Please mark my response correct/helpful as applicable!
Thanks and Regards,
Rahul