var answer = response.responseXML.documentElement.getAttribute("answer");

Bilal Usuf
Kilo Contributor

hi what is the work of "answer"....and what is get Attribute doing here pleae any one can explain me the complete line var answer = response.responseXML.documentElement.getAttribute("answer");

1 ACCEPTED SOLUTION

varunagarwal
ServiceNow Employee
ServiceNow Employee

var answer =response.responseXML.documentElement.getAttribute("answer");



Let us assume we have a function in Script Include :



demofunction: function () {


        var element = this.getParameter('sysparm_parameter');


return 'Hi, This is bind with answer atrribute';


}



Now in client script   -


function myCallBack(response) {


        var answer = response.responseXML.documentElement.getAttribute("answer");


alert(answer); // Output   "Hi, This is bind with answer atrribute"


}



Here "response" is an XML document which contains an attribute "answer" and the value returned from the demofunction binded with the answer attribute.


So response.responseXML.documentElement.getAttribute("answer") gives us the value returned from the script include function.



Award Correct Answer if my Solution Works, Mark helpful if it helps...


View solution in original post

5 REPLIES 5

Gowrisankar Sat
Tera Guru

This link should better explain you, check the GlideAjax section:



https://snprotips.com/blog/2016/2/6/gliderecord-client-side-vs-server-side


Gowrisankar Sat
Tera Guru

The response you get after a server side call(glideajax), will be stored in a format of XML.



You need to parse the response to get the answer attribute:



XML Hierarchy:



response -> responseXML -> documentElement -> Answer(place where the result are stored)


so gowrisankar,



response or answer is fixed keyword here or we can use any varaible name


Yes,



var answer =response.responseXML.documentElement.getAttribute("answer");



var answer -> is a variable you define, even you can define var result


response.responseXML.documentElement.getAttribute("answer"); -> here answer is a value in XML Tag that we receive after server call.