How to hide a variable in MRVS for a specific catalog item only

Aditya02
Tera Guru

I want to Hide a Variable (state_name) which exists in a Multi row Variable set for a specific catalog item. I've tried set display, setvisible by writing a onload and ui policy scripts. but it wo'nt worked. Any one have any idea to hide variable in MRVS for specific cat item.. this requirement is little bit urgent.. 

Thank you in advance.

1 ACCEPTED SOLUTION

Murthy Ch
Giga Sage

@Aditya02 

You can try something like below in MRVS client script:

function onLoad() {
    //Type appropriate comment here, and begin script below
    function getParameterValue(name) {
        name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]");
        var regexS = "[\\?&]" + name + "=([^&#]*)";
        var regex = new RegExp(regexS);
        var results = regex.exec(top.location);
        if (results == null) {
            return "";
        } else {
            return unescape(results[1]);
        }
    }

    var catSysId = getParameterValue('sys_id');
    if (catSysId == "7198552237b1300054b6a3549dbe5dea") { //replace with your cat item sys_id and variable name
        g_form.setDisplay('device_type', false);
    }
}

(=tested)

 

Thanks,
Murthy

View solution in original post

16 REPLIES 16

Debasis Pati
Tera Guru

Hello @Aditya02 ,

Using a Catalog Client Script

  1. Create a Catalog Client Script:

    • Navigate to Service Catalog > Catalog Definitions > Maintain Items.

    • Open the catalog item where the MRVS is used.

    • Scroll down to the Related Links section and click on New under Catalog Client Scripts.

  2. Use the g_form.setVisible() method to hide the variable. However, since MRVS variables are slightly different, you need to target them correctly.

    Example script

    function onLoad() {
    // Check if the catalog item is the specific one
    if (g_form.getValue('sys_id') === 'your_catalog_item_sys_id') {
    // Hide the variable in the MRVS
    var mrvsField = g_form.getControl('multi_row_variable_set_name.variable_name');
    if (mrvsField) {
    mrvsField.style.display = 'none';
    }
    }
    }

    Kindly mark this as correct if this helps you and close this thread so it helps other users and motivates me for helping more.

    Regards,
    Debasis

hello @Debasis Pati ,

I've tried this, but still the field is visible. and I came to know that, 

  • It will return null because g_form.getControl() doesn't directly support accessing variables inside an MRVS.
  • g_form.getControl() works for top-level variables, but it doesn't always find nested variables inside MRVS rows because MRVS fields are handled differently (dynamic rows rendered by the widget, not by standard form fields).

Aditya02_0-1742272710126.png

 

Medi C
Giga Sage

Hi @Aditya02,

 

Please create a UI policy without a condition on your catalog item.

 

in your UI policy action, you can create one for the variable on your variable set and then set its visibility to false.


If you found this helpful, please hit the thumbs-up button and mark as correct. That helps others find their solutions.

Hi @Medi C ,

I tried that also.. but i can able to see internal variables inside the MRVS.. I can see only the Variable set name.

Aditya02_0-1742271388072.png