The CreatorCon Call for Content is officially open! Get started here.

Script Include not working in Record Producer Catalog client script (Xanadu)

alicevalent
Tera Contributor

Hi everyone,

I'm trying to use GlideAjax in a Catalog Client Script to populate the Brand field based on the selected Category. I created a Script Include extending AbstractAjaxProcessor with a method called getBrandsByCategory. However, the client script always logs:

alicevalent_0-1745940639758.png

This is my Script Include (accessible from the global scope and set to "Client Callable"):

var VehicleLookupUtils = Class.create();
global.VehicleLookupUtils = VehicleLookupUtils;

VehicleLookupUtils.prototype = Object.extendsObject(AbstractAjaxProcessor, {

    getBrandsByCategory: function() {
        var categorySysId = this.getParameter('sysparm_category');
        gs.info('[DEBUG] Script Include: getBrandsByCategory called with sysparm_category = ' + categorySysId);

        var brands = [];
        var grBrand = new GlideRecord('x_my_scope_brand');
        grBrand.addQuery('category', categorySysId);
        grBrand.query();

        while (grBrand.next()) {
            var id = grBrand.sys_id.toString();
            var name = grBrand.name.toString();
            gs.info('[DEBUG] Brand found - ID: ' + id + ', Name: ' + name);

            brands.push({ id: id, name: name });
        }

        gs.info('[DEBUG] Total brands found: ' + brands.length);
        return JSON.stringify(brands);
    },

    type: 'VehicleLookupUtils'
});

I originally had a gs.info("script entered"); line before the prototype definition, and I saw that in the system logs — but nothing appears from inside the actual function, so it seems the function is never being triggered.

My Catalog Client Script (onChange for Category) is:

function onChange(control, oldValue, newValue, isLoading) {
  if (isLoading || !newValue) {
    g_form.clearOptions('Brand');
    g_form.addOption('Brand', '', '-- Select a brand --');
    return;
  }

  console.debug('[DEBUG] onChange triggered');
  console.debug('[DEBUG] newValue is valid: ' + newValue);

  var ga = new GlideAjax('VehicleLookupUtils');
  ga.addParam('sysparm_name', 'getBrandsByCategory');
  ga.addParam('sysparm_category', newValue);

  console.debug('[DEBUG] GlideAjax called, waiting for response...');
  ga.getXMLAnswer(function(response) {
    console.debug('[DEBUG] Response from Script Include: ' + response);
    if (!response) {
      console.debug('[DEBUG] No response received. Adding fallback message.');
      g_form.clearOptions('Brand');
      g_form.addOption('Brand', '', '-- No brands available --');
      return;
    }

    try {
      var brands = JSON.parse(response);
      g_form.clearOptions('Brand');
      g_form.addOption('Brand', '', '-- Select a brand --');
      brands.forEach(function(brand) {
        g_form.addOption('Brand', brand.id, brand.name);
      });
    } catch (e) {
      console.error('Error parsing JSON response:', e, response);
    }
  });
}

I double-checked that the Script Include is set to "Client Callable" and globally available.

Any ideas why the Script Include method is not being executed?

1 ACCEPTED SOLUTION

Brad Bowman
Kilo Patron
Kilo Patron

In the Script Include, get rid of the second line and third(blank) lines so that it starts like this:

 

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

    getBrandsByCategory: function() {

 

If you are still not seeing the first/category log, is the Script Include in the same scope as the Client Script? Do you have anything in the Access Controls related list - an ACL with a user role?

View solution in original post

1 REPLY 1

Brad Bowman
Kilo Patron
Kilo Patron

In the Script Include, get rid of the second line and third(blank) lines so that it starts like this:

 

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

    getBrandsByCategory: function() {

 

If you are still not seeing the first/category log, is the Script Include in the same scope as the Client Script? Do you have anything in the Access Controls related list - an ACL with a user role?