how to get the name of catalog in client script onload

Fdeveloper
Kilo Guru

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 : 

sc_catalogs='980f534eeb2bb340b28e03b3ca9619f3'//comapny : how can i do that any suggestion please
1 ACCEPTED SOLUTION

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.

find_real_file.png

View solution in original post

5 REPLIES 5

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.

find_real_file.png