Query and Insert record in same table using business rule

PriyaNarayanan
Kilo Contributor

Hi,

I have a requirement to check a field from a table and then insert/delete a record to the same table.

I am trying to achieve it via business rules, in that case i run the business rule in table x and

then do i need to glide the table x to insert new record?

Kindly clarify me on the same.

Thanks!

Priya

5 REPLIES 5

Manoj Kumar16
Giga Guru

Hi priya,



You can write a business rule in User table-



You can use the below two functions depending on the conditions you have and passing the group sys_id and the user sys_id into the functions.



function insertmember(user, group)


{


var gr=new GlideRecord('sys_user_grmember');


gr.initialize();


gr.user=user;


gr.group=group;


gr.insert();


}


function deletemember(user,group)


{


var gr1=new GlideRecord('sys_user_grmember');


gr.addQuery('user',user);


gr.addQuery('group',group);


gr.query();


if(gr.next())


{


gr.deleteRecord();


}