- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2025 12:33 AM
Hi,
I am unable to get the proper output once I am completed with the script. Kindly help.
function onLoad() {
var sys = g_form.getUniqueValue();
var ga = new GlideAjax('onLoad_Owner_Class');
ga.addParam('sysparm_name', 'onLoad_Owner_Function');
ga.addParam('sysparm_id', sys);
ga.getXML(callBackFunction);
function callBackFunction(response){
var answer = response.responseXML.documentElement.getAttribute('answer');
g_form.setValue('owner', answer);
}
}
ScriptInclude
var onLoad_Owner_Class = Class.create();
onLoad_Owner_Class.prototype = Object.extendsObject(AbstractAjaxProcessor, {
onLoad_Owner_Function: function(){
var keyOwner = this.getParameter('sysparm_id');
var gr = new GlideRecord('sc_cat_item');
gr.addQuery('sys_id', keyOwner);
gr.query();
if(gr.next()){
return gr.owner;
}
},
type: 'onLoad_Owner_Class'
});
Regards
Suman P.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2025 01:53 AM - edited 04-27-2025 01:53 AM
Hi,
I am sorry, I made a mistake, wherein owner is a reference variable in sc_cat_item table, and I have been using gr.owner, I should have used getDisplayValue. Her is the correct code.
var onLoad_Owner_RU = Class.create();
onLoad_Owner_RU.prototype = Object.extendsObject(AbstractAjaxProcessor, {
onLoad_Owner_Function: function(){
var keyOwner = this.getParameter('sysparm_id');
var gr = new GlideRecord('sc_cat_item');
gr.addQuery('sys_id', keyOwner);
gr.query();
if(gr.next()){
return gr.getDisplayValue('owner');
}
},
type: 'onLoad_Owner_RU'
});
Regards
Suman P.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2025 01:53 AM - edited 04-27-2025 01:53 AM
Hi,
I am sorry, I made a mistake, wherein owner is a reference variable in sc_cat_item table, and I have been using gr.owner, I should have used getDisplayValue. Her is the correct code.
var onLoad_Owner_RU = Class.create();
onLoad_Owner_RU.prototype = Object.extendsObject(AbstractAjaxProcessor, {
onLoad_Owner_Function: function(){
var keyOwner = this.getParameter('sysparm_id');
var gr = new GlideRecord('sc_cat_item');
gr.addQuery('sys_id', keyOwner);
gr.query();
if(gr.next()){
return gr.getDisplayValue('owner');
}
},
type: 'onLoad_Owner_RU'
});
Regards
Suman P.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2025 02:23 AM
Hello @Dave_p ,
I copied your Client Script and Script Include to my PDI and it works fine. The field gets populated with the Catalog Item owner.
Does it literally return the string "Record not found" on your end?
Regards,
Robert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2025 02:29 AM
Hi @Robert H,
Actually what happened is that there is exactly same class name already existing. So, it was taking that class instead of what I have written now. I have pasted the working code already. Owner is a reference variable referencing User table, unfortunately, my mistake I literally took it as Single line text variable and used object.owner which should have been object.getDisplayValue('owner'). I updated it, and it started working. Thank you for looking into it.
Regards
Suman P.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-27-2025 03:37 AM
Hello @Dave_p ,
Ok, in this case please mark your question as answered so that community members are aware and don't spend time investigating.
Regards,
Robert