How to change 'created by' as 'System'? Please help

Haceena Shaik
Tera Expert

Hi Team,

 

we have  catalog item to create/insert new user in sys_user table using run script like below. If the user gets created by catalog form, the created by field needs to be changed to "System".

 

 

Run script:
var usr = new GlideRecord('sys_user);
usr.initialize();
usr.first_name = current.variables.v_first_name;
usr.last_name = current.variables.v_last_name;
usr.insert();
//for created by to 'system'
var pr=new GlideRecord('sys_user');
pr.addEncodedQuery('sys_created_by!=AD Integration User^ORsys_created_byISEMPTY^ORsys_created_byISNOTEMPTY^sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()sys_created_by!=AD Integration User^ORsys_created_byISEMPTY^ORsys_created_byISNOTEMPTY^sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()');
pr.query();
if(pr.next()){
pr.sys_created_by='System ';
pr.update();
}

 

7 REPLIES 7

Remove the lines from your script where you are adding another glide record and updating created by

 

 

 

Before this run script in workflow, add a timer for few seconds, this way it will not run in the user session and created will automatically have system in it.

 

-Anurag

-Anurag

Sagar Pagar
Tera Patron

Hi @Haceena Shaik,

 

Just add a Timer activity with 3 seconds time before your Run scripts activity. It will switch teh context from user to system and will update the created by as "system".

 

Thanks,

Sagar Pagar

The world works with ServiceNow

Hi @Haceena Shaik,

 

Good day!

Have you tried by removing the 2nd GlideRecord in Run scripts & adding Timer activity?

Let us know where you stuck?

 

Thanks,

Sagar Pagar

The world works with ServiceNow