Variable reference at "cmdb_ci_computer", configuring to look into another field instead of "name"

AdamUMC
Giga Guru

Hi there,

I have a Service Portal Catalog item which contains a variable that is a reference to "cmdb_ci_computer".
When users fill in this field (variable), they have to fill in a value that is available as name (field "name") within "cmdb_ci_computer".

However, within "cmdb_ci_computer", we have created an additional field. It's called "u_stickernumber". Now I want users in the above mentioned case, to fill in the stickernumber instead of the name, to find/select the right record within "cmdb_ci_computer".

I attempt to achieve this, I gave my variable reference, the following "variable attribute":
"ref_auto_completer=AJAXTableCompleter, ref_ac_columns=u_stickernumber"

Unfortunately, this does not work. Anyone any idea how to do this?

Thanks and kind regards,


Adam

1 ACCEPTED SOLUTION

@AdamUMC 

that's correct, at least they can search with it

If my response helped please mark it correct and close the thread so that it benefits future readers.

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

View solution in original post

8 REPLIES 8

@AdamUMC 

Please close the thread by marking my response as correct so that it helps future members.

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

AdamUMC
Giga Guru

Thanks @Ankur Bawiskar !

The "variable attribute" for variable "assetnumber" is now; ref_auto_completer=AJAXTableCompleter, ref_ac_columns=u_stickernumber, ref_ac_columns_search=true

Now I want to show the stickernumber within my Catalog Item form variable "assetnumber" while;
- Filling in Catalog Item form (OnLoad) - Frontend / Service Portal
- Editting Catalog Item form (OnChange) - Frontend / Service Portal
- While opening Requested and/or Service Catalog Task's - Backend

I've made:
- OnLoad Client Script
- OnChange Client Script
- Script Include

But unfortunately it still does not work. Any idea about the cause? Thanks!


OnLoad Client script:

 

 

function onLoad() {
    var fieldName = 'assetnumber';
    var gFormValue = g_form.getValue(fieldName);

    if (gFormValue) {
        updateStickerNumber(fieldName, gFormValue);
    }
}

function updateStickerNumber(field, sys_id) {
    var ga = new GlideAjax('GetStickerNumber');
    ga.addParam('sysparm_name', 'getStickerNumber');
    ga.addParam('sysparm_sys_id', sys_id);

    ga.getXMLAnswer(function(response) {
        if (response) {
            g_form.setDisplayValue(field, response);
        }
    });
}

 

 


OnChange Client script:

 

 

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    
    updateStickerNumber('assetnumber', newValue); // Roep dezelfde functie aan als in onLoad
}

 

 


Script Include:

 

 

var GetStickerNumber = Class.create();
GetStickerNumber.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    
    getStickerNumber: function() {
        var sys_id = this.getParameter('sysparm_sys_id');
        var gr = new GlideRecord('cmdb_ci_computer');

        if (gr.get(sys_id)) {
            return gr.u_stickernumber;
        }
        return 'Sticker not found';
    }
});

 

 

 

@AdamUMC 

I believe I have answered your original question.

Please close the thread by marking my response as correct and the discussion can continue further.

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

@AdamUMC 

no scripting required. You can use auto populate feature i.e. make the string variable dependent on assetnumber

Auto-populate a variable based on a reference type variable (Utah) 

Also it makes no sense to use this for on-load as when form loads you are not populating any default value in Computer variable

If my response helped please mark it correct and close the thread so that it benefits future readers.

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