- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2022 06:16 AM
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?
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2022 09:32 AM
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'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2022 07:08 AM
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var srvc = g_form.getReference('service_offering', autoOwnedby);
}
function autoOwnedby(srvc) {
alert(srvc.owned_by.getDisplayValue());
if (srvc) {
g_form.setValue('owned_group', srvc.owned_by.getDisplayValue());
}
}
Shakeel Shaik 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2022 07:09 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2022 07:59 AM
Shakeel Shaik 🙂
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2022 08:24 AM
I tried in my PDI
it works
GlideAjax is the standard go to solution for making calls from client side scripts to server side script includes and returning data back to client
1st complete your client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var srcv = g_form.getValue('service_offering'); //variable name of offering
var ga = new GlideAjax("getOwned");
ga.addParam('sysparm_name', 'getOwnedBy');
ga.addParam('sysparm_offering',srcv);
ga.getXML(getOwned);
function getOwned(response)
{
var answer = response.responseXML.documentElement.getAttribute("answer");
g_form.setValue('owned_group',answer); // make sure about the variable name
}
}
Using script include
var getOwned = Class.create();
getOwned.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getOwnedBy: function()
{
var offer = this.getParameter('sysparm_offering');
var gr = new GlideRecord("service_offering");
gr.addQuery('sys_id',offer);
gr.query();
if(gr.next())
{
var owned = gr.owned_by.getDisplayValue();
return owned;
}
},
type: 'getOwned'
});
Result
If its helpful, please mark my answer as correct
Anshu

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-26-2022 09:32 AM
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'
});