Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Help with catalog item form

cicgordy
Tera Guru

Hi all,

I have created a catalog item and I have two reference fields on the form: "office_location" which references the "cmn_location" table and "choose_the_software" which references the "u_software" table.

 

If I select "New York" as office location, I want to then be able to hide the software "Cube3D" optionfrom the choose_the_software reference field.

 

Can anyone help with catalog client script please?

Thanks

12 REPLIES 12

swathisarang98
Giga Sage

Hi @cicgordy ,

 

You can create a script include and in that you can Glide record to location table and return query if name matches New York and call it in 'choose_the_software' variable reference qualifier,

 

I have written this in my pdi on location and software table but change it accordingly to satisfy your requirement

 

Script include:

swathisarang98_0-1709726857752.png

 

 

var getSoftwareDetail = Class.create();
getSoftwareDetail.prototype = {
    initialize: function() {},

    checkSoftware: function(choice) {
        gs.info("Check CHOICE" + choice);

        var gr = new GlideRecord('cmn_location');
        gr.addQuery('sys_id', choice);
        gr.query();
        if (gr.next()) {
            if (gr.name == 'New York')
                return "name!=3D Pinball"; // filter query from ref table
        } else {
            return "nameISNOTEMPTY";
        }

    },

    type: 'getSoftwareDetail'
};

 

 

 

Reference qualifier:

swathisarang98_1-1709726927004.png

 

 

 

javascript: new getSoftwareDetail().checkSoftware(current.variables.location)

 

 

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

Hi @swathisarang98 , 

Thanks for providing this. Not sure I understood what to put instead of "check choice" + "choice" and "choice" in the line below. Can you please clarify according to the field values and names provided in my initial question?

Thanks

cicgordy_0-1709730687542.png

 

@cicgordy , that is just info you can remove that , but choice you can use same because i am passing location sysid through that but

 

swathisarang98_1-1709737760162.png

here also change the encoded query, like go to 'u_software' table and filter out 'name is not Cube3D' and that copy query and paste in the first return or replace above,

 

and in reference qualifier replace 'location' with 'office_location'

 

javascript: new getSoftwareDetail().checkSoftware(current.variables.office_location)

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang