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

thanks , how do i not ignore the rest please

 

By switching your OR conditions to AND conditions, you force it to evaluate the rest (but only if the first condition is true).

Some more examples below.

var A = true;
var B = false;
var C = true;

if (A && B && C){  
  // this will always only evaluate A and B, and C is ignored, since the condition fails on variable A
}
//-----------------------------------------------
var A = true;
var B = false;
var C = true;

if (A && B || C){  
  // this will evaluate all three variables, as long as A is true and B is false.
  // if A is false, the condition fails, and the rest is disregarded
  // if A is true and B is true, then C is not checked, it's not needed since the condition is already true 
}