- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-14-2022 04:02 PM
Hi,
i have a requirement if catalog is company i should hide the button oreder now in catalog item, i create a client script onload and in the client script i have :
function onLoad() {
g_form.setValue('no_order_now', true);
} // it work for me the button is hiding but is hidding in all catalog i should hide the button olnly if the name of catalog of this catalog item is comapnay :
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-14-2022 06:39 PM
Try adding an alert() to check g_form.getUniqueValue() is returning a value.
function onLoad() {
try {
var catSysID = g_form.getUniqueValue();
alert(catSysID);
var ajax = new GlideAjax('ServiceCatalog');
ajax.addParam('sysparm_name', 'getServiceCatalog');
ajax.addParam('sysparm_cat_sys_id', catSysID);
ajax.getXMLAnswer(function(answer) {
if (answer.length > 0) {
if (answer == 'comapny') { // mispelling of 'company' intended?
g_for.setValue('no_order_now',true);
}
}
});
} catch (e) {
alert(e.message);
}
}
If the alert is showing a value, check Script Include's "Client callable" is checked and the name of the Script Include is "ServiceCatalog". If changing the name, ServiceCatalog in Client Script's GlideAjax('ServiceCatalog') also needs to be changed to the new name.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-14-2022 04:41 PM
Hi Fdeveloper,
Instead of using a client script please use a UI policy, where you can give a condition based on the catalog item's name. Thanks.
Please mark my answer as helpful if that solves your concern. Thanks in advance!
Regards,
Nayan
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-14-2022 04:49 PM
Hi
i will do this solution if i should hide the button in ine catalog item i should hide the button for 100 catalog item with the catalog name is company

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-14-2022 05:19 PM
To get the service catalog name from the form, it'll be necessary to create a Client Script that'll call Script Include.
Example:
Client Script
function onLoad() {
try {
var catSysID = g_form.getUniqueValue(); // get the sys_id of the form
var ajax = new GlideAjax('ServiceCatalog'); // 'ServiceCatalog' is the class name of Script Include that I created
ajax.addParam('sysparm_name', 'getServiceCatalog'); // name of function in the Script Include
ajax.addParam('sysparm_cat_sys_id', catSysID); // parameter to pass to the function
ajax.getXMLAnswer(function(answer) {
if (answer.length > 0) {
alert('service catalog name:' + answer);
}
});
} catch (e) {
alert(e.message);
}
}
Script Include:
var ServiceCatalog = Class.create();
ServiceCatalog.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getServiceCatalog: function() {
var catSysID = this.getParameter('sysparm_cat_sys_id'); // get sys_id of the form passed from client script
var gr = new GlideRecord('sc_cat_item');
if (grCat.get(gr.sc_catalogs)) { // query the catalog item table
var grCat = new GlideRecord('sc_catalog');
if (grCat.get(gr.sc_catalogs)) { // query the service catalog table
return grCat.title; // return the title
}
}
return ;
},
type: 'ServiceCatalog'
});
Execution result:
I've set the example form's Catalog to "Service Catalog".
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā02-14-2022 05:33 PM
hi
thank you for your reply don't work i get on console
Uncaught TypeError: Cannot read properties of null (reading 'length')
and i want get the name of catalog i want once the name of catalog is comapny in client script i will do
g_for.setValue('no_order_now',true);