- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 01:53 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 01:55 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 01:55 AM
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
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 03:01 AM
Hi
Can you check if I am doing this correct?
script include:
var HRCaseOptionsSupressOptions = Class.create();
HRCaseOptionsSupressOptions.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getItemsToHideOptions: function() {
var getItemSysIDs = [];
var grGetItems = new GlideRecord('sc_cat_item');
grGetItems.addActiveQuery();
grGetItems.addQuery('sys_idIN', gs.getProperty('sn_hr_sp.HideItemsForHrCaseoptions'));
grGetItems.query();
while (grGetItems.next()) {
getItemSysIDs.push(grGetItems.getValue('sys_id'));
}
return getItemSysIDs;
},
type: 'HRCaseOptionsSupressOptions'
});
client script:
function onLoad() {
//Type appropriate comment here, and begin script below
var itemSysId = g_form.getUniqueValue();
var ga = new GlideAjax('sn_hr_sp.HRCaseOptionsSupressOptions');
ga.addParam('sysparm_name', 'getItemsToHideOptions');
ga.getXMLAnswer(getResponse);
function getResponse(response){
var answer = JSON.parse(response);
alert('sys id from function: ' + answer);
if(itemSysId == answer){
alert('sys ID match');
// hide variables with that variable set one by one
g_form.setVisible('field_name', false);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 03:08 AM
Hi,
you should pass the catalog item sysId to GlideAjax function so that you can compare in script include
var HRCaseOptionsSupressOptions = Class.create();
HRCaseOptionsSupressOptions.prototype = Object.extendsObject(global.AbstractAjaxProcessor, {
getItemsToHideOptions: function() {
var catItemSysId = this.getParameter('sysparm_itemSysId');
if(catItemSysId == gs.getProperty('sn_hr_sp.HideItemsForHrCaseoptions'))
return true;
else
return false;
},
type: 'HRCaseOptionsSupressOptions'
});
Client Script:
function onLoad() {
//Type appropriate comment here, and begin script below
var itemSysId = g_form.getUniqueValue();
var ga = new GlideAjax('sn_hr_sp.HRCaseOptionsSupressOptions');
ga.addParam('sysparm_name', 'getItemsToHideOptions');
ga.addParam('sysparm_itemSysId',itemSysId);
ga.getXMLAnswer(getResponse);
function getResponse(response){
var answer = response;
if(answer.toString() == 'true')
// hide variables with that variable set one by one
g_form.setVisible('field_name', false);
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎08-11-2022 03:18 AM
Thanks
So I need to check if it matches one of the IDs