if condition in script - vancover

levino
Giga Guru

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;
}

 

1 ACCEPTED SOLUTION

Community Alums
Not applicable

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

View solution in original post

6 REPLIES 6

Mark Roethof
Tera Patron
Tera Patron

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

LinkedIn

Unique45
Mega Sage

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.

 

Please mark correct/helpful if this helps you!

Community Alums
Not applicable

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

OlaN
Giga Sage
Giga Sage

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

}