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

Ankur Bawiskar
Tera Patron
Tera Patron

@ss123 

opened_by will be the logged in user? i.e. the user in whose session the workflow activity runs

if yes then do this

task.sys_created_by = gs.getUserName();

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

Hi @Ankur Bawiskar 

 

No, the Opened by is from the variable "Requested by"

 

SabrinaSalazar_0-1689312072780.png

 I need to get the user_id of the Variable Requested by / Task.opened_by and place it to the Task.sys_created_by

 

Thanks.

@ss123 

then do this

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

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

@Ankur Bawiskar 

Still not working 😞