how will you generate a new sys_id by scripting in servicenow?

rohan patil2
Tera Contributor

how will you generate a new sys_id by scripting in servicenow?

and What are the different ways to do so?

1 ACCEPTED SOLUTION

AnirudhKumar
Mega Sage

In addition to Ankur's newRecord() function, you can also use the below code(Used in server side) :

gs.generateGUID()

 

To get the sys id of a record that is about to be created on the client side, you can use:

g_form.getUniqueValue();

View solution in original post

3 REPLIES 3

Ankur Bawiskar
Tera Patron

Hi,

you can use newRecord() method to generate sys_id from script

Remember unless you insert the record it won't be available in the table

var rec = new GlideRecord('incident');
rec.newRecord();
gs.info(rec.sys_id);

Regards
Ankur

@rohan patil 

I could see you marked my response as correct earlier but now it is not.

You can mark only 1 response as correct.

Please mark appropriate response as correct and helpful so that it benefits other members.

Regards
Ankur

AnirudhKumar
Mega Sage

In addition to Ankur's newRecord() function, you can also use the below code(Used in server side) :

gs.generateGUID()

 

To get the sys id of a record that is about to be created on the client side, you can use:

g_form.getUniqueValue();