How to declare value in if loop condition either value A or B
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 hours ago
Hi,
Below is the script, i need to pass the value Group or User to function by declaring if(validateContactType(locationId, 'Authorized Requester', ['Group','User']) ). This script has to print this msg if its not Group or User. please advise the correction in the script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
I don't know if I'm entirely following given the custom table, but it doesn't make any logical sense to execute a for loop INSIDE of a while loop when the for loop is based on the length of an array that is initialized in the while loop. So as written the for loop will ALWAYS run only once, for each record returned by the GlideRecord, unless and until it returns true. Also, is the value of u_group_user actually either 'Group', 'User', etc. (case-sensitive)? It seems like typeValue[i] will then never = ['Group,'User'].
So I would say first either close the while loop before executing the for loop:
while (gr.next()) {
var typeValue = [];
typeValue.push(gr.getValue('u_group_user'));
}
for (var i = 0; i < typeValue.length; i++) {
if (typeValue[i] != allowedTypes) {
gs.print("inside the loop" + gr.u_location.name + typeValue[i] +allowedTypes);
return true;
}
}
or get rid of the for loop all-together if you want to evaluate against the allowedTypes during each iteration:
while (gr.next()) {
if (gr.getValue('u_group_user' != allowedTypes) {
gs.print("inside the loop" + gr.u_location.name + gr.getValue('u_group_user') +allowedTypes);
return true;
}
}
But in either case you need to change the if condition to something that evaluates against the array. Here's one approach:
if (allowedTypes.toString().indexOf(typeValue[i]) == -1) { //u_group_user value not 'Group' or 'User'