- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 03:55 AM
Hi all,
I have requirement, if approver and user and same, approval should not be triggered.
Script which has been written is not working. Could anyone help me out.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 04:07 AM
Hi Suvedha,
Just try this below code and make sure you are using "Approval User" activity
var appAr = [];
var approvers = new GlideRecord('sys_user_grmember');
approvers.addQuery('group', current.assignment_group);
approvers.query();
while(approvers.next()) {
if(approvers.user.toString() != current.requested_by.toString()) {
workflow.info('APPROVER = ' + approvers.user.toString());
answer.push(approvers.user.toString());
}
}
answer = appAr;
Hope this information helps you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-29-2023 04:47 AM
Hi @Suvedha
You can exclude the requested for in through encodedQuery itself :
/* 1. Declare array */
var answer = [];
/* 2. get user from variable */
var user = current.variables.Requested_For;
/* 3. Glide record on group member table */
var grpMem= new GlideRecord('sys_user_grmember');
grpMem.addEncodedQuery('group=477a05d153013010b846ddeeff7b1225^user!= '+ user); // this will exclude if requester for if its same
grpMem.query();
while(grpMem.next())
{
var approver = grpMem.getValue('user');
answer.push(approver.toString());
}
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 06:49 AM
Hi Vishal,
Encoded query is not working now. Please find the attached screenshot, it should give only one, it is giving two, some issue is happening in encodedquery.
Could you please help me in this
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 06:58 AM
Hi @Suvedha
Can you open the list view of group member table and filter the list with above query
& check...!!
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 07:38 AM
Hi Vishal,
In list view of table, it is working correctly.
I am confused, why I am not able to achieve in background script
Thanks & regards,
Suvedha
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 07:46 AM
Hi Vishal,
I got it, this is because of the space encoded query.
Thank you for the help.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-04-2023 07:54 AM
Cool....!!
ServiceNow Developer
I know one thing, and that is that I know nothing.
- Socrates