
- Post History
- Subscribe to RSS Feed
- Mark as New
- Mark as Read
- Bookmark
- Subscribe
- Printer Friendly Page
- Report Inappropriate Content
07-19-2019 09:03 AM - edited 07-26-2024 01:07 AM
Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
What is shared in this article, might not be best practice. Just sharing this to explore possibilities, find openings in ServiceNow, and have a mindset that your imagination is your limitation. |
Hi there,
Just for fun this time, how to create your own (User) sys_id. I noticed there wasn't a Community article on this topic yet, so decided to write an article again.
Note: I just used sys_user as an example, though you could apply this in multiple places.
Case
When creating new records, ServiceNow automatically generates a unique sys_id. Though at some rare places in the system you'll notice there isn't actually a 32-character sys_id used but just a string. What the?!
So could we do this ourselves? For example on a User record, with your own firstname.lastname or your nickname? Yes, you can!
How to
You only have to apply setNewGuidValue. Note this will only work for new records, not for updating records.
I also applied autoSysFields. Just because I wanted to apply a custom Created date, so this would be my actual date of birth 🙂.
var gr = new GlideRecord('sys_user');
gr.initialize();
gr.setValue('user_name', 'mark.ragavan');
gr.setValue('first_name', 'Mark');
gr.setValue('last_name', 'Ragavan');
gr.setValue('sys_created_on', '1983-05-01 12:30:00');
gr.setNewGuidValue('mark.ragavan');
gr.autoSysFields();
gr.insert();
Result
A User record has been created with the above code. Have a look at the XML to verify that your custom sys_id has been applied.
---
And that's actually it! So easy to apply.
C |
If this content helped you, I would appreciate it if you hit bookmark or mark it as helpful.
Interested in more Articles, Blogs, Videos, Podcasts, Share projects I shared/participated in? |
Kind regards,
Mark Roethof
ServiceNow Technical Consultant @ Paphos Group
---
- 4,809 Views

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
This is stunning Mark.
Thanks for this information, it's very helpful 🙂
Cheers.

- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Awesome Mark 🙂
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Is there a way to delete or update such record(CI) where sys_id is some other value.?
Not able to achieve same with fix script
var gr = new GlideRecord('cmdb_ci_win_server');
gr.addEncodedQuery('nameSTARTSWITHGabc');
gr.query();
gs.log(gr.getRowCount());
gs.log(gr.getDisplayName());
gs.log(gr.sys_id.toString()); // this is coming undefined
if (gr.next()) {
gs.log("Record is found to delete");
//gr.deleteRecord();
gr.setNewGuidValue('c7a5d7fd873e4550e67dc8c80cbb35e3');
gr.update();
gr.setWorkflow(false);
gr.autoSysFields(false);
}


- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
Hi,
the setNewGuidValue method appears to only be applicable when inserting a new record. It isn't used to overwrite what is already there.
Please mark reply as Helpful, if applicable. Thanks!
- Mark as Read
- Mark as New
- Bookmark
- Permalink
- Report Inappropriate Content
It works perfectly in scoped applications also