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

Harsh Vardhan
Giga Patron

create after business rule on table1 and mention the trigger condition current.priority=='<select your value>'



var gr = new GlideRecord('table2');


gr.initialize();


gr.name = current.name;


gr.field= current.field;


gr.date= current.date;


gr.type= current.type;


gr.insert();



let me know if you have any further question.


please validate field name , i just randomly mentioned the name..


Hey Harsh,



I tried this code and this worked in a case where tables are interlinked with each other or childs of same parent.But in my scenario tables are not linked with each other in any case however the field names,types are same.Both tables are part of same app. but are not linked with each other.



Here is the code that i tried:



var nr = new GlideRecord('u_maintenance_window');// now it doesnot create any record for me in u_maint_window table


nr.initialize();


nr.event_name = current.u_name;


nr.insert();



however if i try the same code on a differentapp where both tables are a referenced from a parent it works fine.Did I miss something in here?



Regards,


Akshay


is the table name u_maintenance_window or u_maint_window ? Also, can you please check if there is any data-policy which is causing an issue.


It should work, i don't think both the tables are needs to be related to each other, since here you are not trying to set any field with parent-child relationship.