Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

UI Action to Create Record in Another Table.

dfry123
Mega Expert

Hello,

I have a parent table (table1) that extends the CMDB table. I also have another table that extends table1 (table2).

I created a UI action on Table 2 that will create a record on Table1 with the data from Table2. This works without issue except the choice lists I have on Table 2 does not go over to Table 1 even though the choice lists contain the same names/values. I tested by forcing the value like this "phone.u_phone_manufacturer = "Apple";"   and it worked without issue.  

Any help would be appreciated... my script is below.

var phone = new GlideRecord('table1');

                  phone.initialize();

                        phone.u_phone_manufacturer = current.u_requested_manufacturer();

                          phone.assigned_to = current.assigned_to();
                          phone.u_type = current.u_type();
phone.u_color = "blue" ;
                         

                 

phone.insert();

action.setRedirectURL(phone);
action.setReturnURL(current);

1 ACCEPTED SOLUTION

nthumma
Giga Guru

var phone = new GlideRecord('table1');


                  phone.initialize();



                        phone.u_phone_manufacturer = current.u_requested_manufacturer;


                          phone.assigned_to = current.assigned_to;


                          phone.u_type = current.u_type;


phone.u_color = "blue" ;


                       


               


phone.insert();


action.setRedirectURL(phone);


action.setReturnURL(current);



can you try like above without parenthesis '()'?


View solution in original post

5 REPLIES 5

nthumma
Giga Guru

var phone = new GlideRecord('table1');


                  phone.initialize();



                        phone.u_phone_manufacturer = current.u_requested_manufacturer;


                          phone.assigned_to = current.assigned_to;


                          phone.u_type = current.u_type;


phone.u_color = "blue" ;


                       


               


phone.insert();


action.setRedirectURL(phone);


action.setReturnURL(current);



can you try like above without parenthesis '()'?


Thank you! That worked.


T_6
Tera Contributor

Hello, I tried this, and the record was created in table1 and it was opening when I clicked the UI action. But the record is not shown in the list view of the table1 and I can't find where the record is saved. Can someone please tell me the solution

var phone = new GlideRecord('x_563957_e_governa_problem');


phone.initialize();

phone.u_complainer = current.u_string_1; //Name
phone.u_complainer_address = current.u_string_2; //address
phone.u_choice_2 = current.u_choice_6; //deptartment
phone.u_string_1 = current.u_string_4; //problem
phone.description = current.description; //description

phone.insert();


action.setRedirectURL(phone);


action.setReturnURL(current);

This is my code.

veena_kvkk88
Mega Guru

Hi Darrell,



Like srnewbie said, removing the parenthesis should fix the issue (hopefully). But may i ask what the purpose of this is? Table 2 is extended from Table 1, so the record in table2 is essentially a part of 1. So whats the point of creating a redundant record? Especially since all the fields in table1 are available in table2?