- 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
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:30 AM
Hi Prashant,
Thanks for your response.
Approvals are generated now, but the if condition is not validating correctly.
Even if approver and requester are same, it going inside the if loop.
In the log it is satisfying with one of the group member.
Thank you,
Suvedha
- 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
09-29-2023 05:08 AM
It worked!!
Thank you