- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 08:38 AM
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();
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 08:41 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 08:41 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 08:55 AM
Hi Maik ,
Thanks for the quick response , the goal is not to have a blank record inserted . I just want to copy over the values in a new record on u_test and then get the sys id for that new record and populate u_test_r1_number on the demand end with that value.
I thought that the line below lets me create a new record on u_test
var gr1 = new GlideRecord('u_test');
I was using the line below to get the sys id for that new record:
var chgSysId = gr1.insert();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 09:03 AM
var chgSysId = gr1.insert(); < this creates the blank record. You are then using the sys id of the blank record and overriding the current objects sys id with that new value using the update statement.
then you are inserting a new record.
As
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-16-2022 09:10 AM
Removing the line solved the blank record issue , but how would I get the sys id for the new record that was created on u_test ?