Create a new record with a UI action

__17
Tera Expert

I would like to create a UI action like the one below and implement a spec that sets the value by default when creating a new record.

However, when I execute a UI action on the record list screen, a "No records selected" popup is output.

Can you tell me the UI action to create a new record?

var new_rec = new GlideRecord("table_name");

new_rec.initialize();

new_rec.setValue("field_name1","value1");
new_rec.setValue("field_name2","value2");
new_rec.setValue("field_name3","value3");

action.setRedirectURL(new_rec);
1 ACCEPTED SOLUTION

var new_rec = new GlideRecord("table_name");

new_rec.initialize();

new_rec.setValue("field_name1","value1");
new_rec.setValue("field_name2","value2");
new_rec.setValue("field_name3","value3");

action.openGlideRecord(new_rec);

 

The above code solved it!

I didn't use it because I thought that ".insert ()" would save the record.
I was also considering closing the record without saving it.

Thank you.

View solution in original post

5 REPLIES 5

Mark Roethof
Tera Patron
Tera Patron

Hi there,

Where is the .insert()?

Or do you want a new record to open on your screen, which is not saved yet, though with some fields populated already?

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020-2022 ServiceNow Community MVP
2020-2022 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

var new_rec = new GlideRecord("table_name");

new_rec.initialize();

new_rec.setValue("field_name1","value1");
new_rec.setValue("field_name2","value2");
new_rec.setValue("field_name3","value3");

action.openGlideRecord(new_rec);

 

The above code solved it!

I didn't use it because I thought that ".insert ()" would save the record.
I was also considering closing the record without saving it.

Thank you.

Don't see any changes to the original code? So what the solution now? Or was my answer sufficient and correct?

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020-2022 ServiceNow Community MVP
2020-2022 ServiceNow Developer MVP

---

LinkedIn
Community article, blog, video list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

without having insert() the record won't be inserted

Don't you wish to insert the record and then open the record?

Regards
Ankur

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