Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Set Display Value on Catalog Client Script - not sys_id

Henrik Jutterst
Kilo Sage

I have this client script that's running when ever a serial number is changed. What I'm looking for is to set the model name to the text field. But the scipt returns the sys_id instead of the Dispaly value.

I've seen some posts here but I'm missing the last piece to understand.

Here's my Catalog UI Script:

function onChange(control, oldValue, newValue, isLoading) {
		if (isLoading || newValue == '') {
		return;
	}

	var grSerialNumber = new GlideRecord('cmdb_serial_number');
	var snSysID = g_form.getValue('serialNR');
	grSerialNumber.addQuery('sys_id', snSysID);
	grSerialNumber.query(myCallbackFunction);
	g_form.addInfoMessage(snSysID);


	function myCallbackFunction(gr) {
		while (gr.next()) {
			//set Display Value to model filed
			g_form.setValue('model', gr.cmdb_ci);
		}
	}
}
7 REPLIES 7

Willem
Giga Sage
Giga Sage

Have you considered making the Model variable a Reference? That way you can set the sys_id as per your script and it will show the user the display value.

Otherwise you need to create a Client callable script include and call that from your client script to get the display value. As I don't think get displayValue works on a glide record callback.

Just to be sure you can try it like this:

function myCallbackFunction(gr) {
        while (gr.next()) {
            //set Display Value to model filed
            g_form.setValue('model', gr.getDisplayValue('cmdb_ci'));
        }
    }

 

The idea of using a reference filed for the model did strike me but I was hoping that it could be done using just this client script.

But there's not really a reason why I can't use a reference, so maby I'll go with that solution instead.

Buy the way. Thanks for the quick answer!

Willem
Giga Sage
Giga Sage

Using a Client callable script include you can do it like this:

Catalog Client script:

Set UI Type appropriate. For example to All

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }

    var ga = new GlideAjax('global.customCmdbUtil');
    ga.addParam('sysparm_name', 'getSerialNumber');
    ga.addParam('sysparm_serialnr', g_form.getValue('serialNR'));
    ga.getXMLAnswer(ajaxResponse);
    function ajaxResponse(answer) {
        g_form.addInfoMessage(snSysID);
        g_form.setValue('model', answer);
    }
}

 

 

For the Client callable script include:

var customCmdbUtil = Class.create();
customCmdbUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getSerialNumber: function () {
        var grSerialNumber = new GlideRecord('cmdb_serial_number');
        var snSysID = this.getParameter('sysparm_serialnr');
        grSerialNumber.addQuery('sys_id', snSysID);
        grSerialNumber.query();
        return grSerialNumber.getDisplayValue("cmdb_ci");
    },

    type: 'customCmdbUtil'
});

Wow, thanks! I'll give it a try!

But, the sys_id that I got from my initial code (in my question) returns the sys_id for the CI-record and not the sys_id for the model on the ci-record.

But there is no way to dot-walk there, because it gets undefined

function myCallbackFunction(gr) {
	while (gr.next()) {
		g_form.addInfoMessage('gr.cmdb_ci.model_id: ' + gr.cmdb_ci.model_id);
		g_form.setValue('model', gr.cmdb_ci.model_id);
	}
}

 

Is it possible to dotwalk with the example you provided using GlideAjax?