- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2017 06:50 AM
Hi ,
i had created one table OUTAGE and created fields (fields present in incident table ) now my requirement is if i select any Reference Field(eg.incident table) in outage table then it should populate all the fields related to that record
for this i had done through GlideAjax in that for multiple fields i had defined obj, but i am unable to fetch the values
here is the script which i have tried
Script include:
var outage_utils = Class.create();
outage_utils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCaller: function() {
var result = "";
var rm = this.getParameter('sysparm_pnt');
var gr = new GlideRecord('incident');
gr.addQuery('sys_id',rm);
gr.query();
if (gr.next()){
//if (gr.get(rm)){
var obj = {};
obj.u_short_description = gr.short_description;
obj.u_impact= gr.impact;
obj.u_urgency=gr.urgency;
var json = new JSON();
result = new JSON().encode(obj);
gs.log('answeris '+result,'LS');
return result;
}
// }
// else return "No user1 found.";
},
/*gr.addQuery('sys_id',rm);
gr.query();
if (gr.next()) {
result = gr.short_description;
}
gs.log('Inside SI>> '+result,'MJ');*/
type: 'outage_utils'
});
Client Script :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('outage_utils');
ga.addParam('sysparm_name', 'getCaller');
ga.addParam('sysparm_pnt', newValue);
ga.getXML(displayUser);
// ga.get(record.sys_id);
}
function displayUser(response){
var answer = response.responseXML.documentElement.getAttribute("answer");
answer = JSON.parse(answer);
//alert('Answer is >> '+answer);
//g_form.setValue('u_short_description', answer);
g_form.setValue('u_short_description', answer.short_description);
g_form.setValue('u_impact',answer.impact);
g_form.setValue('u_urgency',answer.urgency);
// g_form.setValue('description',answer.name);
}
Could you please help me in this
Thanks in Advance
Regards,
Sasidhar
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2017 09:09 AM
Did you try with earlier script i have provided?
if you want to continue with Json part, try to change the line of code
var obj = {};
obj.u_short_description = gr.getValue('short_description').toString();
obj.u_impact= gr.getValue('impact').toString();
obj.u_urgency=gr.getValue('urgency').toString();
change these line and try.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2017 06:55 AM
Can you try the alerts and log messages in client script and script include to check where it on wards its not working.
This one you can do it with one more way as well, check 2.1.1.2 Returning Multiple Values
http://wiki.servicenow.com/index.php?title=GlideAjax#Returning_Multiple_Values
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2017 07:11 AM
I guess i did not find any issue in your script.
Try this one,
Script include:
var outage_utils = Class.create();
outage_utils.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getCaller: function() {
var result = "";
var rm = this.getParameter('sysparm_pnt');
var gr = new GlideRecord('incident');
gr.addQuery('sys_id',rm);
gr.query();
if (gr.next()){
this._addDetails("short_description", gr.short_description);
this._addDetails("impact", gr.impact);
this._addDetails("urgency", gr.urgency);
}
},
_addDetails : function(name, value) {
var favs = this.newItem("favorite");
favs.setAttribute("name", name);
favs.setAttribute("value", value);
},
type: 'outage_utils'
});
Client Script :
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('outage_utils');
ga.addParam('sysparm_name', 'getCaller');
ga.addParam('sysparm_pnt', newValue);
ga.getXML(displayUser);
// ga.get(record.sys_id);
}
function displayUser(response){
var userInfo = serverResponse.responseXML.getElementsByTagName("favorite");
for(var i = 0; i < userInfo.length; i++) {
var name = userInfo [i].getAttribute("name");
var value = userInfo [i].getAttribute("value");
if(name=='short_description'){
g_form.setValue('u_short_description',value);
}
if(name=='impact'){
g_form.setValue('u_impact',value);
}
if(name=='urgency'){
g_form.setValue('u_urgency',value);
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2017 08:49 AM
Hi ,
Thank you very much balaji ,
I had kept logs in my script fetching the result but log came as answeris {"u_impact":{},"u_short_description":{},"u_urgency":{}}
in my script till obj it is correct i guess after that encode is not happening there i am facing problem. .
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-09-2017 09:09 AM
Did you try with earlier script i have provided?
if you want to continue with Json part, try to change the line of code
var obj = {};
obj.u_short_description = gr.getValue('short_description').toString();
obj.u_impact= gr.getValue('impact').toString();
obj.u_urgency=gr.getValue('urgency').toString();
change these line and try.