Display value from field in above reference

Adam M
Tera Contributor

Hi

I have a reference field that looks up a computer in alm_hardware table.

I want to display the serial number 'serial_number' in a form of the computer selected in the above reference field.

5 REPLIES 5

Allen Andreas
Administrator
Administrator

Hi,

You'd have to change the "display" value for that table to be the serial number field.

This is a platform wide change (meaning wherever else references to this table are used, serial number would display there as well) and would be done by accessing the dictionary record for that table and then setting the display column to "true" for the relevant field.

Please mark reply as Helpful/Correct, if applicable. Thanks!


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Hi Adam,

I hope my reply above was at least Helpful, even if it confirmed a change you wouldn't want to make, haha.

Take care! 🙂


Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!

Ankur Bawiskar
Tera Patron
Tera Patron

@Adam M 

I agree with point shared by Allen.

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

Hitoshi Ozawa
Giga Sage
Giga Sage

Hi Adam,

Add a read-only field "Serial Number" (name:serial_number) to the form below computer field.

Client script:

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
    var ajax = new GlideAjax('AlmHardware');
    ajax.addParam('sysparm_name', 'getSerialNumber');
    ajax.addParam('sysparm_sys_id', newValue);
    ajax.getXMLAnswer(function(answer) {  // call script include
		alert(answer);
        if (answer.length > 0) {
            g_form.setValue('serial_number', answer); // set serial number to field "serial number"
        }
    });
}

Script Include. Name: AlmHardware

var AlmHardware = Class.create();
AlmHardware.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getSerialNumber: function() {
        var sysId = this.getParameter('sysparm_sys_id');
        var grHardware = new GlideRecord('alm_hardware');
        if (grHardware.get(sysId)) {
            return grHardware.serial_number;
        }
        return;

    },
    type: 'AlmHardware'
});

Execution result:

find_real_file.png