Is it possible to hide a variable like "Address" from a catalog item

B Ashok
Tera Guru

Is it possible to hide a variable like "Address" from a catalog item in ServiceNow once the request is fulfilled. Untill the RITM Is fulfilled variable should be visible, once it's fulfilled variable value or variable with value should be hide. 

Example : 
Catalogue ITEM  : ABC

                  Variable : Address
I tried with Catalouge UI policy and UI Policy both not supporting. I tried with below Script inlcude and catalogue client script not working please help me on this. 

 

Catalogue Client script : 

function onLoad() {
    var ritmID = g_form.getParameter('sysparm_id');
    if (ritmID) {
        var ga = new GlideAjax('RITMStateCheck');
        ga.addParam('sysparm_name', 'getRITMState');
        ga.addParam('sysparm_ritm_id', ritmID);
        ga.getXMLAnswer(function(answer) {
            if (answer == '6') { // 6 = Fulfilled
                g_form.setDisplay('address_1', false); // 'address_1' is the variable name 
            }
        });
    }
}

Script include : 

// Name: RITMStateCheck
// Accessible from: Client Callable
var RITMStateCheck = Class.create();
RITMStateCheck.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getRITMState: function() {
        var ritmID = this.getParameter('sysparm_ritm_id');
        var gr = new GlideRecord('sc_req_item');
        if (gr.get(ritmID)) {
            return gr.state.toString(); // Returns state as string (6 for Fulfilled)
        }
        return '';
    }
});
5 REPLIES 5

Arun_Manoj
Mega Sage

Hi @B Ashok ,

 

 

Correct Approach for Hiding Variables on RITM form

You should use a UI Policy on the sc_req_item table, scoped to the variable, and use a GlideRecord script condition to detect state.

Goal:

Hide the variable from RITM view if the request is in Fulfilled (state = 6).


 Solution

1. Create a Catalog UI Policy

  • Table: sc_req_item

  • Run on Load: (checked)

  • Global: if needed

  • Conditions: None (we’ll use script condition)

2. Add a Script Condition

Under the "Advanced" checkbox in the UI Policy, use this:

 

 
(function() { return current.state == 6; // 6 = Fulfilled })();
 

3. UI Policy Action

  • Variable name: address_1

  • Visible: (unchecked)

This ensures the variable is hidden only when the RITM is Fulfilled.


Optional: Use a Client Script on sc_req_item (Not preferred)

If you still want to use a client script, it must be a standard UI script (not catalog client script), and only runs in the RITM form context:

 

 
// UI Type: All // Table: sc_req_item // Type: onLoad
if (g_form.getTableName() === 'sc_req_item')
{
var state = g_form.getValue('state');
if (state == '6') {
g_form.setDisplay('variables.address_1', false);
}
}

Use 'variables.<variable_name>' to refer to catalog variables on the RITM form.

 

 

Please mark it as helpful. solution is fine.

 

thanks

Arun

Ankur Bawiskar
Tera Patron
Tera Patron

@B Ashok 

you can use normal client script onLoad of RITM table, don't use catalog client script

function onLoad() {
	// use correct state value to compare
    if (g_form.getValue('state').toString() == '6') {
        g_form.setDisplay('variables.address_1', false);
    }
}

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@B Ashok 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

@B Ashok 

Hope you are doing good.

Did my reply answer your question?

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader