- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2023 10:41 PM
Is there a way to create a record in GlideRecord by specifying a sys_id?
For example, I would like to create a record with sys_id "12345678901234567890123456789012" in a script.
Is it possible?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2023 11:21 PM
You can try using setNewGuidValue() to set the sys_id to what you want.
For example:
var inc = new GlideRecord('incident');
inc.initialize();
inc.short_description = "Testing";
inc.setNewGuidValue("12345678901234567890123456789012");
inc.insert();
Read more in the docs for GlideRecord
GlideRecord | ServiceNow Developers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2023 11:21 PM
You can try using setNewGuidValue() to set the sys_id to what you want.
For example:
var inc = new GlideRecord('incident');
inc.initialize();
inc.short_description = "Testing";
inc.setNewGuidValue("12345678901234567890123456789012");
inc.insert();
Read more in the docs for GlideRecord
GlideRecord | ServiceNow Developers
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2023 11:46 PM
Try below code
var gr = new GlideRecord('incident');
gr.initialize();
gr.description = 'Test123";
gr.setNewGuidValue("12345678901234567890123456789012");
gr.insert();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-21-2023 11:55 PM
try this
setNewGuidValue() is used to set sysId on record
gs.generateGUID() -> will generate new random sysId
var rec = new GlideRecord('incident');
rec.initialize();
rec.setValue('short_description', 'Testing');
rec.setNewGuidValue(gs.generateGUID());
rec.insert();
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-22-2023 12:20 AM
Hi,
Providing a custom string as a sys_id is not a best practice as that sys_id may already be tagged to a record.
The best method would be to use "gs.generateGUID" which will always generate a unique string of sys_id to be consumed.
Hope this helps.
Regards,
Dhruv