- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 09:40 PM
Hi Community,
The following client scripting showing alert message as 'undefined'.
Client Script:-
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
//Type appropriate comment here, and begin script below
var service={'servicelink':'','servicegroup':''};
alert('hii' + newValue);
//alert(g_form.getValue(newValue).getDialogBox());
var globalInvAjax = new GlideAjax('GlobalInvestment');
globalInvAjax.addParam('sysparm_name','getServiceLineAndServiceGroup');
globalInvAjax.addParam('sysparm_servicenetwork',newValue);
globalInvAjax.getXML(getServiceDetails);
function getServiceDetails(response){
answer = response.responseXML.documentElement.getAttribute("answer");
//alert(answer);
service=answer;
//alert(JSON.parse(answer));
//alert(answer.servicegroup);
//service=JSON.parse(answer);
alert(service.serviceline);
}
}
Script Include:-
var GlobalInvestment = Class.create();
GlobalInvestment.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getServiceLineAndServiceGroup : function(){
gs.addInfoMessage('hello from sc');
gs.addInfoMessage(this.getParameter(' '));
var service={'serviceline':'','servicegroup':''};
var globalInv = new GlideRecord('u_global_investment_data');
globalInv.addQuery('sys_id',this.getParameter('sysparm_servicenetwork'));
globalInv.query();
if(globalInv.next()){
gs.addInfoMessage('1 '+globalInv.u_service_line);
gs.addInfoMessage('2 '+globalInv.u_service_group);
service.serviceline=globalInv.u_service_line;
service.servicegroup=globalInv.u_service_group;
}
var ser=service.serviceline + ', '+service.servicegroup;
//return new global.JSON().encode(service);
//return JSON.stringify(service);
return service;
},
type: 'GlobalInvestment'
});
Thanks,
Ankita
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 09:57 PM
update as this
var GlobalInvestment = Class.create();
GlobalInvestment.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getServiceLineAndServiceGroup : function(){
var service = {};
var globalInv = new GlideRecord('u_global_investment_data');
globalInv.addQuery('sys_id',this.getParameter('sysparm_servicenetwork'));
globalInv.query();
if(globalInv.next()){
service.serviceline = globalInv.u_service_line.toString();
service.servicegroup = globalInv.u_service_group.toString();
}
return JSON.stringify(service);
},
type: 'GlobalInvestment'
});
client script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var globalInvAjax = new GlideAjax('GlobalInvestment');
globalInvAjax.addParam('sysparm_name','getServiceLineAndServiceGroup');
globalInvAjax.addParam('sysparm_servicenetwork',newValue);
globalInvAjax.getXML(getServiceDetails);
function getServiceDetails(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
var jsonData = JSON.parse(answer);
alert(jsonData.serviceline);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 09:46 PM
Hi @Ankita Kolhe,
In your script include you are returning service, it should be ser. Try it and let me know.
Thanks,
Sagar Pagar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 09:49 PM
Hi Sagar,
I want to return the object & retrieve the same on client script.
Thanks,
Ankita
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 09:57 PM
update as this
var GlobalInvestment = Class.create();
GlobalInvestment.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getServiceLineAndServiceGroup : function(){
var service = {};
var globalInv = new GlideRecord('u_global_investment_data');
globalInv.addQuery('sys_id',this.getParameter('sysparm_servicenetwork'));
globalInv.query();
if(globalInv.next()){
service.serviceline = globalInv.u_service_line.toString();
service.servicegroup = globalInv.u_service_group.toString();
}
return JSON.stringify(service);
},
type: 'GlobalInvestment'
});
client script
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var globalInvAjax = new GlideAjax('GlobalInvestment');
globalInvAjax.addParam('sysparm_name','getServiceLineAndServiceGroup');
globalInvAjax.addParam('sysparm_servicenetwork',newValue);
globalInvAjax.getXML(getServiceDetails);
function getServiceDetails(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
var jsonData = JSON.parse(answer);
alert(jsonData.serviceline);
}
}
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-01-2023 10:13 PM
Hi Ankur,
Thanks for the response.
Tried with the above code but alert message is showing as [object Object].