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:25 AM
What is the issue your getting?
any error message?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2022 02:29 AM
Hi @ABHAY_M ,
Thanks for Quick response..
With the script it is not updating 'created_by' as 'System'.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2022 02:35 AM
Hi,
If the script executes in the system session then this field will automatically have system. Otherwise you cannot change it afterwards.
Where is this script running?
-Anurag
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2022 02:48 AM
Hi,
Script is in workflow. Once the catalog item is submitted, it is showing 'created by' in user record as catalog item submitted user. I want it to 'system'. It's not working..