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 weeks 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
3 weeks 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'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Brad, Thanks for reply.. I have attached log screenshot..The error message displays into location contact field itself. i have shared the entire script - there are 4 functions - check if not user contact type, check if not group contact type, check if other contact type(contacttype must be user or group), check if groupcontact type( contact type must be user or other). my script works correctly for first two function. but it didnt works correctly rest of the two.
pls advise the correction in the script:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
With this version of the script, it would be helpful to add a log line inside the for loop as the first step to show which u_group_user record is being evaluated, and the allowedTypes it is being evaluated against. Note that with this structure, if ANY u_group_user values are not User or Group it will return true. You are showing 5 records for this location that are a User or Group, but are there any other records for the same location?