Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

How to get the Sys id after creating a record via script

shaik_irfan
Tera Guru

 

Hi,

 

On the Service portal once user clicks the button i am getting all the details from the html using input method and i am able to create a record with below script

 

var gr = new GlideRecord('u_qa');
gr.initialize();
gr.question = input.u_questions;
gr.name = input.name;
gr.insert();

 

this goes and create a record u_qa table but i want the sys id of the created of record as a response. can anyone please help me how to do that ?

1 ACCEPTED SOLUTION

sachin_namjoshi
Kilo Patron
Kilo Patron

use below

 

var gr = new GlideRecord('u_qa');
gr.initialize();
gr.question = input.u_questions;
gr.name = input.name;
var s = gr.insert();
gs.info(s);

View solution in original post

5 REPLIES 5

sachin_namjoshi
Kilo Patron
Kilo Patron

use below

 

var gr = new GlideRecord('u_qa');
gr.initialize();
gr.question = input.u_questions;
gr.name = input.name;
var s = gr.insert();
gs.info(s);

"very very" thank you so much... i spent time trying other way, but its help me

Elijah Aromola
Mega Sage

If you store the value of .insert to a variable you can use it.

See below script

var gr = new GlideRecord('u_qa');
gr.initialize();
gr.question = input.u_questions;
gr.name = input.name;
var sys_id = gr.insert();

Ankur Bawiskar
Tera Patron
Tera Patron

@shaik.irfan 

You can get the sys_id of the record by storing it in variable

you can then re-use it

var gr = new GlideRecord('u_qa');
gr.initialize();
gr.question = input.u_questions;
gr.name = input.name;
var sysId = gr.insert();

Mark Correct if this solves your issue and also mark 👍 Helpful if you find my response worthy based on the impact.
Thanks
Ankur

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader