Why it is auto-populating sys_id for a record in a catalog item?

Krika
Kilo Contributor

Hello All,

When I'm auto-populating the 'service_offering' - Owned by field (which is a reference field) it is just populating the sys_id of the its Owned by (owned_by) record. 

In my catalog item Owned group variable type is a Single Line Text 

On my client script I have also tried getDisplayValue() which is not working for me, can anyone suggest me a solution for this?

find_real_file.png

find_real_file.png

find_real_file.png

1 ACCEPTED SOLUTION

Hitoshi Ozawa
Giga Sage
Giga Sage

Krika,

What is the type of field "owned_by" in the table "service_offering"? Can it be that's it a reference field? It's not possible to dot-walk using getReference. Convert the script to use ajax call to Script Include.

Client Script

function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
    var ajax = new GlideAjax('GetGroupInfo');
    ajax.addParam('sysparm_name', 'getOwnedBy');
    ajax.addParam('sysparm_service_offering', newValue);
    ajax.getXMLAnswer(function(answer) {
        if (answer.length > 0) {
            g_form.setValue('owned_group', answer);
        }
    });
}

Script Include

var GetGroupInfo= Class.create();
GetGroupInfo.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getOwnedBy: function() {
        var sysId= this.getParameter('sysparm_service_offering');
        var grService = new GlideRecord('service_offering');  // replace with table name that contains "service_offering"
        if (grService.get(sysId)) {
            return grService.owned_by.name.toString();  // replace "name" with column name in table referenced by owned_by
        }
        return;
    },
    type: 'GetGroupInfo'
});

View solution in original post

14 REPLIES 14

Hi

add this on line 5:

var srvc = g_form.getReference...........

 

and share script, copay and paste here

 

 

Thanks:)

Thanks,
Shakeel Shaik 🙂

Hi,

 

Here is one reference video, How to use getReference  in Client Script
https://youtu.be/yMt8ZYnAV7s

 

If my response is helpful, then Please mark as Correct Answer/Helpful.

Please check and let us know.

Thanks 🙂

Shakeel Shaik.

 

Thanks,
Shakeel Shaik 🙂

Hi,

This too returns the sys_id of the record

 

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

var srvc = g_form.getReference('service_offering', autoOwnedby);
}
function autoOwnedby(srvc){
if(srvc){
g_form.setValue('owned_group',srvc.owned_by);

}

}

Once check with

1. srvc.owned_by.name

2. srvc.getDisplayValue('owned_by');

Thanks,
Shakeel Shaik 🙂

1.srvc.owned_by.name - which is returning undefined

2.srvc.getDisplayValue('owned_by'); - which is not returning anything