How to hide some variable set variables from only some catalog items

Khalnayak
Tera Guru

Hello,

I need some advise and help please.

We are using a variable set which sets variables for multiple catalog items / record producers.

This variable set is included in many items, and the variable set calls script includes to check logic and show fields accordingly.

We have a requirement to hide some of the options from a few catalog items, without affecting the others.

What is best way I can hide some fields on certain catalog items please?

have tried using UI policies on the actual catalog items that need hiding but that does not work.

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

something like this

onLoad catalog client script which Applies on Variable Set

function onLoad(){
	var itemSysId = g_form.getUniqueValue();
	if(itemSysId == 'your Catalog item SysId'){
		// hide variables with that variable set one by one
	}
}

If you are thinking hard-coding is not best practice then use onLoad client script + GlideAjax and within that ajax function use getProperty() to get catalog item sysId and then compare and return true/false

Regards
Ankur

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

View solution in original post

13 REPLIES 13

Hi,

then do this

var HRCaseOptionsSupressOptions = Class.create();
HRCaseOptionsSupressOptions.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {

    getItemsToHideOptions: function() {
        var catItemSysId = this.getParameter('sysparm_itemSysId');
        if(gs.getProperty('sn_hr_sp.HideItemsForHrCaseoptions').indexOf(catItemSysId) > -1)
            return true;
        else
            return false;        
    },

    type: 'HRCaseOptionsSupressOptions'
});

Regards
Ankur

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

Thanks @Ankur Bawiskar  this is working now but only when I click try it from the cat item.

In the ESC the fields are not hiding, but the alerts are appearing in both UIs

UI type for client script is set to All

Hi,

Glad to know that my script worked.

g_form.getUniqueValue() should give you catalog item sysId in both Native + Portal

What comes in alert for g_form.getUniqueValue() in Native?

Regards
Ankur

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

Thanks @Ankur Bawiskar .

all the alerts are working. I am getting different sys ids for both native and portal, but both are matching the sys id in URL so the script is working fine.

It's just not hiding it in portal but hiding in native.

Hi,

so the logic is working fine.

it's not hiding in portal means is there any other script which is running in portal which is doing the opposite.

Regards
Ankur

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