Create a business rule to insert a record when a record is created in different table

akshay707
Tera Contributor

I want to create a business rule that create and takes the value from different table. For ex:

table1 fields- name , date, priority(1,2,3), type.

table2 fields-name,date,type

whenever i select priority as 1 in table1 ,it should create a new record in table2.

I tried it with Gliderecord.initialize but not sure how that works.

Note: Both table are part of same application but the values are not inherited/refreneced from each other.

1 ACCEPTED SOLUTION

it does not matter if there is any relationship build or not. record should be create. i tried at my end and it's working..


find_real_file.png



find_real_file.pngfind_real_file.png



Result:



find_real_file.png



Note: Please validate your script and check if something is conflicting .


View solution in original post

8 REPLIES 8

it does not matter if there is any relationship build or not. record should be create. i tried at my end and it's working..


find_real_file.png



find_real_file.pngfind_real_file.png



Result:



find_real_file.png



Note: Please validate your script and check if something is conflicting .


Surendra Raika1
Kilo Guru

Hello Akshay,




I hope response from Harsh has helped you.



initialize, newRecord are functions which sets the boilerplate to get a record created. (initialize sets an empty field boilerPlate and newRecord considers default and assign sys_id, doesn't wait for insert to assign sys_id unlike initialize).



try this out :



var gr = new GlideRecord('att_tdi');//lol you may use any table to understand the behaviour



gs.addInfoMessage(gr.sys_id);


gs.addInfoMessage(gr.isNewRecord());


gr.insert();


gs.addInfoMessage(gr.sys_id);



gr.initialize();


gs.addInfoMessage(gr.sys_id);


gs.addInfoMessage(gr.isNewRecord());


gr.insert();


gs.addInfoMessage(gr.sys_id);



gr.newRecord();


gs.addInfoMessage(gr.sys_id);


gs.addInfoMessage(gr.isNewRecord());


gr.insert();


gs.addInfoMessage(gr.sys_id);




So do you want to get a copy of P1 in some another table(Hope you want to keep the P1 in sync with table1); I would ask you opt for async if and use of a script include keeping these records in sync.



BR


Surendra


Hi Surendra,



I got what is explained by everyone maybe for my app it is not working because i might have messed with ACL's . Just wanted check if script include is really required to have these records in sync??. they are working fine for me when I applied async BR on a different application.



Regards,


Akshay


No push to use Script Include and even async; if its working fine



my bit was to help you understand initialize and NewRecord.



Just think about code reuse and modularity (nothing to do anything specific with ServiceNow).



Cheers.