- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 04:47 AM
var userCriterias = ['6b6df061ff2121009b20ffffffffff44','0b5b0e6453631300afffddeeff7b1201']; var userMatches = sn_uc.UserCriteriaLoader.userMatches(gs.getUserID(), userCriterias); gs.info(userMatches);
Trying to implement this validation in a catalog to check if the user has met the user criteria for which I am using an onload script to retrieve the userID and passing it to server side script through glideajax. Which returns back null value all the time. Have put on logs to see if the right values are passed on, which seems to be good. Let me know if any changes to be made with the code.
Client script:
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 05:49 AM
Please update your script include code like below:
var UserCriteriaValidator = Class.create();
UserCriteriaValidator.prototype = Object.extendsObject(AbstractAjaxProcessor, {
checkUserMatches: function () {
var userID = this.getParameter('sysparm_userID');
var userCriterias = [];
userCriterias.push(this.getParameter('sysparm_userCriterias'));
// Check if the user matches the given criteria
var check = sn_uc.UserCriteriaLoader.userMatches(userID, userCriterias);
// Return the result
return check.toString();
},
type: 'UserCriteriaValidator'
});
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 06:03 AM - edited 12-19-2023 06:04 AM
I'm glad it worked for you Imran as I identified it earlier.
@Anil Lande Could you explain us why it worked when we converted the return value to string? Is it required to convert return values to sting?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 08:32 PM - edited 12-19-2023 08:33 PM
Hi @Utpal Dutta
Actual solution was to change the datatype of 2nd parameter (userCriterias) passes to API. It should be of type Array.
var userCriterias = [];
userCriterias.push(this.getParameter('sysparm_userCriterias'));
var check = sn_uc.UserCriteriaLoader.userMatches(userID, userCriterias);
I just use toString to avoid further errors. No need to convert return values if your are returning string,Integer or boolean. It automatically get converted as string.
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 05:12 AM - edited 12-19-2023 05:13 AM
Hi Danish,
A common issue that I see while using GlideAjax is Script Include should be returning values in string format. If you're returning a variable 'check' then please validate that variable contains string value & not object.
To do so please validate it by logging 'check' variable type.
gs.log(typeof check);
If above log returns 'string' as output then its fine. Otherwise in your last line where you've written (return check). Replace it with below:
return JSON.stringify(check);
The above statement will stringify any any object and then return.
If my answer helps then please mark it correct.
Thanks,
Utpal
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 05:40 AM
seems to return boolean.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2023 05:43 AM - edited 12-19-2023 05:47 AM
Please convert it to string and then return. Your script will run as expected.
To convert you can use IF statement.
if(your_variable_containing_bool_value){ //This block of code will only run when boolean value is true
return 'true';
}
else{
return 'false';
}
Also, don't forget to mark my answer correct!
Thanks