- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-16-2017 11:55 PM
I have to delete record that is selected in catalog form. so i have written code below in runscript activity in workflow. the record is not deleting from table only few times it is deleting. can anyone help me on this. thanks
script
var gr = new GlideRecord('u_training_courses');
//gr.addQuery('sys_id',current.variables.Requested_for);
gr.addQuery('active',true);
gr.query();
gr.next();
gr.deleteRecord();
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2017 08:53 PM
Hi Bala,
1. Field name - 'Requested_for' ('R' in caps). ServiceNow converts the field names to be smaller case by default. Need to change it as 'requested_for' or copy/paste the correct field name.
2. Field name to be queried with is 'group.name' and not 'group'. Make sure you are giving the correct group name (with correct case too).
Please try the below modified script.
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group.name','itil_group'); // group to group.name and make sure the group name is correct with right case
gr.addQuery('user',current.variables.requested_for); // change from Requested_for to requested_for
gr.query();
if(gr.next())
{
gr.deleteRecord();
}
gs.addInfoMessage("Testing " + current.variables.requested_for.getDisplayValue() + " removed");
Please try and share the message if it is not getting deleted.
Hope this helps. Mark the answer as correct/helpful based on impact.
Thanks
Antin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2017 08:22 PM
I had updated like this ....i am getting messages after approval but record is not deleted .
if(current.variables.Confirmation == 'remove')
{
var gr = new GlideRecord('sys_user_grmember');
//gr.setDisplayValue('sys_id',current.variables.Requested_for);//requested_for field is reference for user table .
//gr.setDisplayValue('group','itil_group');///group has itil_group values
gr.addQuery('group','itil_group');
gr.addQuery('sys_id',current.variables.Requested_for);
gr.query();
gs.addInfoMessage('query');
gr.next();
gr.deleteRecord();
gs.addInfoMessage("Testing " + current.variables.Requested_for.getDisplayValue() + " removed");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2017 08:51 PM
If i select these option then after approval, record should be deleted
on which table these field are ? if you want to delete the record then script should be on the table which hold these fields not the sys_user_grmember.
var gr = new GlideRecord('TASK TABLE NAME');
gr.addQuery('requested_for', current.variables.Requested_for);
gr.addQuery('role_allocated', 'itil')
gr.addQuery('confirmation', 'remove')
gr.query();
if(gr.next())
gr.deleteRecord();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2017 08:53 PM
Hi Bala,
1. Field name - 'Requested_for' ('R' in caps). ServiceNow converts the field names to be smaller case by default. Need to change it as 'requested_for' or copy/paste the correct field name.
2. Field name to be queried with is 'group.name' and not 'group'. Make sure you are giving the correct group name (with correct case too).
Please try the below modified script.
var gr = new GlideRecord('sys_user_grmember');
gr.addQuery('group.name','itil_group'); // group to group.name and make sure the group name is correct with right case
gr.addQuery('user',current.variables.requested_for); // change from Requested_for to requested_for
gr.query();
if(gr.next())
{
gr.deleteRecord();
}
gs.addInfoMessage("Testing " + current.variables.requested_for.getDisplayValue() + " removed");
Please try and share the message if it is not getting deleted.
Hope this helps. Mark the answer as correct/helpful based on impact.
Thanks
Antin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2017 09:04 PM
HI
not working getting undefined for "current.variables.requested_for"
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-22-2017 09:10 PM
Yes, that says your field names are not correct. Can you confirm the correct field names for 'variables' and 'requested_for'?