- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2024 05:20 AM
Hi Team
the second part of my if statement is not evaluating
Thanks
Levino
// answer should equate to a single user sys_id or comma-separated list of users (sys_ids)
//DO NOT remove the following line:
var curRec = new GlideRecord(advTABLE);
curRec.get(advRECORD); // RITM will be the active sc_req_item record passed in from approval workflow
//TODO: add your code below to use the above variable. For example:
answer = getApprovers(curRec);
function getApprovers(ritm) {
var user = ritm.variables.requested_for.toString();
var dl_approvers = ritm.variables.distribution_list.u_owner.toString();
var distribution_list = ritm.variables.distribution_list.toString();
var ritm_approvers = '';
var selection = ritm.variables.dl_action.toString();
if (selection == 'modify_members' || selection == 'modify_group_details' || selection == 'remove_group') {
//check if user is a member of the dl owners
var isOwner = dl_approvers.indexOf(user);
if(isOwner == -1 || distribution_list != '89c7c7641b48e41409a30fe8dc4bcb65'){
ritm_approvers = dl_approvers;
}
}
return ritm_approvers;
}
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2024 10:35 AM
Hi @levino ,
Please try to make your if condition like below
if( dl_approvers != user || distribution_list != '89c7c7641b48e41409a30fe8dc4bcb65' )
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2024 05:42 AM
Hi there,
Try to add some debugging. Up to where is your script working, from which point isn't it, what is the values of the variables, are the variables as expected, etc..
Adding debugging will spot your issue within a few minutes instead of wasting several hours.
Kind regards,
Mark Roethof
Independent ServiceNow Consultant
10x ServiceNow MVP
---
~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2024 06:19 AM
Hello @levino,
Add logs and check the values of each variable. This will help you identify the issue.
example:
gs.info('dl_approvers - ' +dl_approvers);
And check logs in log(syslog) table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2024 10:35 AM
Hi @levino ,
Please try to make your if condition like below
if( dl_approvers != user || distribution_list != '89c7c7641b48e41409a30fe8dc4bcb65' )
Please mark my answer correct and helpful if this works for you
Thanks and Regards
Sarthak

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-25-2024 01:45 PM
Hi,
Is your the first part of the IF statement true?
If so, the rest is not evaluated, that's standard boolean logic, the rest does not need to be evaluated if the first condition of many OR conditions is true.
Like this:
var A = true;
var B = false;
var C = true;
if (A || B || C){
// this will always only evaluate A, and the rest is ignored
// it's not needed since the condition is already fulfilled
}