GlideAjax returns null value

imran rasheed
Tera Contributor
 userMatches - Validates whether the user matches any of the user criteria's listed in the array and returns a boolean value ie true or false 
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:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
   if(newValue !='')
   {
 
// Get the current user's ID
    var userID = g_form.getValue('requested_for');

    // Define the user criteria
    var userCriterias = 'b4b142379303311083a1b61efaba1045';

    // Make a GlideAjax call to validate user criteria on the server side
    var ga = new GlideAjax('UserCriteriaValidator');
    ga.addParam('sysparm_name', 'checkUserMatches');
    ga.addParam('sysparm_userCriterias', userCriterias); // Convert to JSON string
    ga.addParam('sysparm_userID', userID);
   

    ga.getXML(callBack);

    function callBack(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
        alert("Answer is " +answer);
       
   }
}
}
 
Script include:
 
var UserCriteriaValidator = Class.create();
UserCriteriaValidator.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    initialize: function() {
    },

checkUserMatches: function () {
      var userID = this.getParameter('sysparm_userID');
      var userCriterias = 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;
   },

   type: 'UserCriteriaValidator'
});
1 ACCEPTED SOLUTION

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'
});
Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

View solution in original post

15 REPLIES 15

Passed values this way it worked. 🙂

 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();