The CreatorCon Call for Content is officially open! Get started here.

UI Action accidentally creating two records on click

Mike S3
Giga Expert

The goal of my UI action is to copy some fields from a demand record to a custom table called test . It also updates a field on the current demand record with a reference to the newly created record. 

The fields are copied over , and the field on demand is being updated with a reference to the new record on test . However , on click its creating two records in the test table . One that's completely blank and one with the values. 

I believe the issue is because I'm using current.update() and gr1.insert() together , but I haven't figured out how to get the UI action to work as intended without them. 

var gr1 = new GlideRecord('u_test');
var chgSysId  = gr1.insert(); 
current.u_test_r1_number =  chgSysId   ;
current.update();
gr1.initialize();
gr1.u_demand_number_reference =current.sys_id;
gr1.u_assigned_lead = current.u_assigned_lead;
gr1.u_intake_decision_note = current.u_intake_note;
gr1.u_request_name = current.short_description;
gr1.u_client_name= current.u_client_name;
gr1.u_test_request_type="review1";
gr1.u_crm_lead= current.u_brm_lead;
gr1.u_request_status ="draft";
gr1.insert();
1 ACCEPTED SOLUTION

Maik Skoddow
Tera Patron
Tera Patron

Hi

the following two lines make no sense

var gr1 = new GlideRecord('u_test');
var chgSysId  = gr1.insert(); 

What is your intention by inserting a blank record into 'u_test' ?

Kind regards
Maik

View solution in original post

5 REPLIES 5

Mike S3
Giga Expert

Thanks for your help @emir  and @Maik Skoddow , it finally clicked and I fixed the issue