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 11:13 PM
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();
}