We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

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

Ashutosh Munot1
Kilo Patron

Yes YOu can do it...Can you explain me what is your requirement so that i can help you in coding....



You can query same table and can insert or update it...depends on what you want to achieve


Hello Ashutosh,



I have a true/false field in group table and whenever members are inserted/deleted to a group(say y) with this field set to true, i want to insert/delete members in a different group (say x).



I have business rule in sys_user_grmember.



Please let me know if you need further details.



Thanks!


Priya


So you want to insert a member or delete a member from a group when this field is false.....or you only want to check this true/false field...



question is: when u want to delete/insert members, when it is true or when it is false


Manoj Kumar16
Giga Guru

Yes you need to use GlideRecord-



To delete a record:



var gr = new GlideRecord('incident')


gr.addQuery('sys_id','99ebb4156fa831005be8883e6b3ee4b9'); //to delete one record


gr.query();


gr.next();


gr.deleteRecord();


}



Refer this document-GlideRecord - ServiceNow Wiki



To insert a record:



var gr = new GlideRecord('to_do');


gr.initialize();


gr.name = 'first to do item';


gr.description = 'learn about GlideRecord';


gr.insert();