How to change 'created by' as 'System'? Please help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2022 02:15 AM - edited 10-04-2022 02:17 AM
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();
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2022 02:58 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2022 02:51 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2022 06:57 PM
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