logo

NJP

Create your own (user) sys_id

Import · Jul 19, 2019 · article

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 image.

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.

image

---

And that's actually it! So easy to apply.

Kind regards,

Mark Roethof

ServiceNow Technical Consultant @ Paphos Group---

LinkedIn

Labels:

image

View original source

https://www.servicenow.com/community/developer-articles/create-your-own-user-sys-id/ta-p/2299146