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

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

Hello @Murthy Ch ,


Where should I run this script—in the Variable Set or the Catalog Item?

 

I tried using it in the Catalog Item to setDisplay and setVisible, but it didn't work. Also, I have a doubt: if we write this inside an MRVS, getParameterValue will return the Variable Set's sys_id. So, when we compare it with the Catalog Item's sys_id, it will obviously return false.

If we write this in the Catalog Item, what is the purpose of checking those conditions? Since this client script runs only for this specific Catalog Item, wouldn’t the check be redundant?

Hi @Aditya02 

You need to write the script in MRVS catalog client script (in variable set)

The getParamterValue is the function which returns catalog item sys_id. So, I believe it works and tested in my PDI before sharing the code. Keep me posted if you have any questions.

Happy to answer

Thanks,
Murthy

Hello @Murthy Ch ,

 

I tried this, but i am getting null as sys_id. and i am seeing that unescape is deprecated.

Aditya02_0-1742273308222.pngAditya02_1-1742273314818.png

 

@Aditya02 

you won't know the URL within MRVS client script

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