We're reclaiming inactive PDIs to keep them available for active builders. Learn what's changing, who's affected, and how to protect your work. Read More

Quality Gate Status Falied on Catalog Client Script

Esteban_Neri
Tera Contributor

I created a Catalog Client Script to auto-populate a field in a form based on "Assignment Group" field. The info of that field is used in a Flow action to populate assignment group on a new SCTASK. It works fine if I use the sys_id in the script, however I'm now required to do it using system properties to pass quality gates. Could you please advice on the easiest way to implement this?

 

Client Script Code:

function onLoad() {
    //Type appropriate comment here, and begin script below
    var ig = g_form.getValue('assignment_group');
    // Assigment group IG sys_ID: ##########################
    // Assigment group IT sys_ID :##########################
 
    if (ig === '##########################') {
        g_form.setValue('field_it_1_1', '##########################');
        g_form.setReadOnly('field_it_1_1', true);
    }

    /*This is approach is good to set the value of IT fields, however to populate assignment group on SCTASKS created using flow action "New Create IT Tasks" does not work, assignment group shows empty.
 
        var assignment_group = g_form.getDisplayBox('assignment_group').value;
        if (assignment_group === 'IG_group') {
            g_form.setValue('field_it_1_1', 'IT_group');
            g_form.setReadOnly('field_it_1_1', true);
        }*/

}
1 ACCEPTED SOLUTION

Tanushree Maiti
Tera Patron

Hi @Esteban_Neri 

 

To successfully pass quality gates and avoid hardcoded sys_id in your Catalog Client Script, you should transition to using GlideAjax paired with a Script Include.

 

  1. Create the Script Include
  • Name: GetCatalogItemProperty
  • Client callable: Check the box true

 

var GetCatalogItemProperty = Class.create();

GetCatalogItemProperty.prototype = Object.extendsObject(AbstractAjaxProcessor, {

   

    getSysProperty: function() {

        var propertyName = this.getParameter('sysparm_property_name');

        return gs.getProperty(propertyName);

    },

 

    type: 'GetCatalogItemProperty'

});

 

  1. Update your Catalog Client Script

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || newValue === '') {

        return;

    }

    if (newValue == 'your_condition_here')  //Update your condition

 {

        var ga = new GlideAjax('GetCatalogItemProperty');

        ga.addParam('sysparm_name', 'getSysProperty');

        ga.addParam('sysparm_property_name', 'your.system.property.name'); // Define your system property key here

                ga.getXMLAnswer(function(answer) {

            if (answer) {

                g_form.setValue(' field_it_1_1', answer);

            }

        });

    }

}

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

View solution in original post

4 REPLIES 4

Brad Bowman
Mega Patron

You should use GlideAjax to call a Script Include which will simply use gs.getProperty to return the value of that property to the client, which you can then use to set the variable value.

Tanushree Maiti
Tera Patron

Hi @Esteban_Neri 

 

To successfully pass quality gates and avoid hardcoded sys_id in your Catalog Client Script, you should transition to using GlideAjax paired with a Script Include.

 

  1. Create the Script Include
  • Name: GetCatalogItemProperty
  • Client callable: Check the box true

 

var GetCatalogItemProperty = Class.create();

GetCatalogItemProperty.prototype = Object.extendsObject(AbstractAjaxProcessor, {

   

    getSysProperty: function() {

        var propertyName = this.getParameter('sysparm_property_name');

        return gs.getProperty(propertyName);

    },

 

    type: 'GetCatalogItemProperty'

});

 

  1. Update your Catalog Client Script

function onChange(control, oldValue, newValue, isLoading) {

    if (isLoading || newValue === '') {

        return;

    }

    if (newValue == 'your_condition_here')  //Update your condition

 {

        var ga = new GlideAjax('GetCatalogItemProperty');

        ga.addParam('sysparm_name', 'getSysProperty');

        ga.addParam('sysparm_property_name', 'your.system.property.name'); // Define your system property key here

                ga.getXMLAnswer(function(answer) {

            if (answer) {

                g_form.setValue(' field_it_1_1', answer);

            }

        });

    }

}

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

This is great! I'll try this. Thank you very much!

ajmalmuhamm
Tera Contributor

Hi @Esteban_Neri ,
Since this is a
Catalog Client Script, you can't access system properties directly from client-side code using gs.getProperty(). A common approach is:

  1. Store the required Assignment Group sys_ids in System Properties.
  2. Create a Script Include (client callable) or GlideAjax that reads the system properties on the server.
  3. Call the Script Include from your Catalog Client Script to retrieve the sys_id values, then compare and set the field accordingly.

This keeps the sys_ids out of the client script, satisfies quality gate requirements, and still allows your Flow to receive the correct sys_id for creating the SCTASK.

If the values are only needed by the Flow, an even better approach is to read the system properties directly within the Flow Action or a server-side script, avoiding the need to expose the sys_ids to the client altogether.