The CreatorCon Call for Content is officially open! Get started here.

Getting item name from RITM

MWright1
Giga Guru

Hi all,

We have a requirement to hide a tab from view if the catalog item is not called "Add Procedure".

 

I create a script include as follows:

var ritm_details_by_number = Class.create();
ritm_details_by_number.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    ritm_info: function() {
        var result = this.newItem("result");
        var ritm = this.getParameter('sysparm_number');

        // I tested this section in Script Background and it does return the item name...       
        var gr = new GlideRecord("sc_req_item");
        gr.addQuery('number', ritm);
        gr.query();

        if (gr.next()) {
            var cat = gr.cat_item;
            var gi = new GlideRecord("sc_cat_item");
            gi.addQuery('sys_id', cat);
            gi.query();

            if (gi.next()) {
                var item = gi.getDisplayValue();
		result.setAttribute("item_catid", cat);
		result.setAttribute("item_name", item);
            }
        }
    },
    type: 'ritm_details_by_number'
});

 

Then tested a couple of client scripts:

var ritm = g_form.getValue('cat_item');

var item;
var ga = new GlideAjax("ritm_details_by_number");
ga.addParam("sysparm_name", "ritm_info");
ga.addParam("sysparm_number", ritm);
ga.getXML(ajaxResponse(serverResponse, item));

function ajaxResponse(serverResponse, item) {
    var result = serverResponse.responseXML.getElementsByTagName("result");
    item = result[0].getAttribute("item_name");
}

alert(item);   // item is undefined.
if (item == "Add Procedure"){
    g_form.setSectionDisplay('tab_name', true);
}else{
    g_form.setSectionDisplay('tab_name', false);
}

 

I have also tried:

var ritm = g_form.getValue('cat_item');
var item;
var ga = new GlideAjax("ritm_details_by_number");
ga.addParam("sysparm_name", "ritm_info");
ga.addParam("sysparm_number", ritm);
ga.getXML(ajaxResponse);

function ajaxResponse(serverResponse) {
    var result = serverResponse.responseXML.getElementsByTagName("result");
    item = result[0].getAttribute("item_name");		
	if (item == "Add Procedure"){
		g_form.setSectionDisplay('id_details', true);
	}else{
		g_form.setSectionDisplay('id_details', false);
	}
}

 

Neither of them worked.  Any assistance would be highly appreciated.  

 

1 ACCEPTED SOLUTION

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

I do not think you need to have a glideajax if it is on RITM table you can use the below:-

 

function onLoad() {
var item=g_form.getDisplayBox('cat_item').value;
if (item == "Add Procedure"){
		g_form.setSectionDisplay('id_details', true);
	}else{
		g_form.setSectionDisplay('id_details', false);
	}

}

 

Please mark my answer as correct based on Impact.

View solution in original post

2 REPLIES 2

Saurav11
Kilo Patron
Kilo Patron

Hello,

 

I do not think you need to have a glideajax if it is on RITM table you can use the below:-

 

function onLoad() {
var item=g_form.getDisplayBox('cat_item').value;
if (item == "Add Procedure"){
		g_form.setSectionDisplay('id_details', true);
	}else{
		g_form.setSectionDisplay('id_details', false);
	}

}

 

Please mark my answer as correct based on Impact.

MWright1
Giga Guru

Thank you so much!  I didn't know i can use it like that.