Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Catalog Item Script Problem

Tomas Linde
Tera Expert

Good morning everyone,
I have created a Catalog Client Script and an Include Script so that a user that contains the keyword "Manager" in its firstname and/or lastname cannot be selected in a variable of type reference and displays a message in case an attempt is made to select .
The fact is that it is not executed correctly and I cannot find the error, I would appreciate your help, greetings.

 

* Catalog Client Script: 

function onChange(control, oldValue, newValue, isLoading) {
  if (isLoading) {
    return;
  }

  var requestedFor = g_form.getValue('for_whom_are_you_requesting_this_item');

  var ga = new GlideAjax('ALOCatalogItemOtherSoftwareAJAX');
  ga.addParam('sysparm_name', 'isManager');
  ga.addParam('sysparm_user', requestedFor);

  ga.getXML(checkManager);
}

function checkManager(response) {
  var isManager = response.responseXML.documentElement.getAttribute("answer");

  if (isManager == 'true') {
    g_form.showFieldMsg('for_whom_are_you_requesting_this_item', 'The user is not allowed.', 'error');
  } else {
    g_form.clearFieldMsg('for_whom_are_you_requesting_this_item');
  }
}

 

* Script Include:

var ALOCatalogItemOtherSoftwareAJAX = Class.create();
ALOCatalogItemOtherSoftwareAJAX.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	isManager: function() {
		var userSysId = this.parameter ('sysparm_user');
        var gr = new GlideRecord('sys_user');
        if (gr.get(userSysId)) {
            return (gr.getValue('firstname').toLowerCase().indexOf('manager') !== -1 ||
                    gr.getValue('lastname').toLowerCase().indexOf('manager') !== -1);
        }
        return false;
    },

    type: 'ALOCatalogItemOtherSoftwareAJAX'
});

 

 

1 REPLY 1

SunilKumar_P
Giga Sage

Hi @Tomas Linde, Can you try var userSysId = this.getParameter('sysparm_user'); instead of this.parameter? Also, the issue with the field names of first_name and last_name in the script include and make sure the Client Callable is checked on the script include.

 

 

 

var ALOCatalogItemOtherSoftwareAJAX = Class.create();
ALOCatalogItemOtherSoftwareAJAX.prototype = Object.extendsObject(AbstractAjaxProcessor, {

	isManager: function() {
		var userSysId = this.getParameter('sysparm_user');
        var gr = new GlideRecord('sys_user');
        if (gr.get(userSysId)) {
            return (gr.getValue('first_name').toLowerCase().indexOf('manager') !== -1 ||
                    gr.getValue('last_name').toLowerCase().indexOf('manager') !== -1);
        }
        return false;
    },

    type: 'ALOCatalogItemOtherSoftwareAJAX'
});

 

Client script:

function onChange(control, oldValue, newValue, isLoading) {
  if (isLoading) {
    return;
  }
  var ga = new GlideAjax('ALOCatalogItemOtherSoftwareAJAX');
  ga.addParam('sysparm_name', 'isManager');
  ga.addParam('sysparm_user', newValue);
  ga.getXML(checkManager);
}

function checkManager(response) {
  var isManager = response.responseXML.documentElement.getAttribute("answer");
  if (isManager) {
    g_form.showFieldMsg('for_whom_are_you_requesting_this_item', 'The user is not allowed.', 'error');
  } else {
    g_form.clearFieldMsg('for_whom_are_you_requesting_this_item');
  }
}

 

Thanks,
Sunil