Query and Insert record in same table using business rule
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2016 10:40 PM
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
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2016 10:49 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2016 11:03 PM
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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-25-2016 12:30 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-24-2016 10:55 PM
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();