Populate location based on caller's field

renu8
Giga Contributor

I tried populating location field using g_form.getReference() it worked. but I am not able to achieve it using GlideAjax. Kindly help.

1 ACCEPTED SOLUTION

Mark Roethof
Tera Patron
Tera Patron

Did this work for you? Still any questions? Could you please update. I do see you are posting other questions again. So please resond to the topics your posting and where people are responding to.

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

View solution in original post

17 REPLIES 17

Did you check the article I mentioned? Contains detailed explanation and examples.

Concerning getXMLAnswer vs getXML: retrieving only the answer versus retrieving the whole documents, so performance.

Client Side Scripting: Go for GlideAjax (with getXMLAnswer)!

If my answer helped you in any way, please then mark it as helpful.

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Hi,

getXMLAnswer() saves you a line of code every time you use it. There shouldn't be any noticeable difference in speed, though this method is probably guaranteed to be slightly slower as it runs at least one more line of code each time.  So ease of use vs minuscule difference in speed. 

with getXMLAnswer() you no longer need this line of code each time.

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

 

Please Mark Correct/Helpful answer if it help you in any way.

Thanks and Regards,

Kunal

Hi there,

To understand more about getXMLAnswer vs getXML, read below article:
getXMLAnswer vs getXML

Kind regards,
Mark
2020 ServiceNow Community MVP
2020 ServiceNow Developer MVP

---

LinkedIn
Community article list

 

Kind regards,

 

Mark Roethof

Independent ServiceNow Consultant

10x ServiceNow MVP

---

 

~444 Articles, Blogs, Videos, Podcasts, Share projects - Experiences from the field

LinkedIn

Hi, Please find the below code that I have written but still no luck, location field is showing blank.

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
    
    var ga=new GlideAjax('AutopopulatedetailsC');
    ga.addParam('sysparm_name',setEmail);
    ga.addParam('sysparm_loc',g_form.getValue('caller_id'));
    ga.getXML(getResponse);
    function getResponse(response)
    {
        //var answer=response.responseXML.documentElement.getAttribute('answer');
        //return answer;
        var answer=response;
        g_form.setValue('location',answer);
        
    }

   //Type appropriate comment here, and begin script below
   
}

Script Include:

var AutopopulatedetailsC = Class.create();
AutopopulatedetailsC.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    setEmail:function(){
    var gr=new GlideRecord('sys_user');
    gr.addQuery('sys_id',this.getParameter('sysparm_loc'));
    gr.query();
    if(gr.next())
    {
    return gr.location.name.toString();
    }
    },

    type: 'AutopopulatedetailsC'
});

Hi,

 

And remove  var answer=response; because you are not using getXMLanswer() in client script.

So that's why value is not get.

Use this below script in client script.

 

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
    
    var ga=new GlideAjax('AutopopulatedetailsC');
    ga.addParam('sysparm_name',setEmail);
    ga.addParam('sysparm_loc',g_form.getValue('caller_id'));
    ga.getXML(getResponse);
    function getResponse(response)
    {
      var answer=response.responseXML.documentElement.getAttribute('answer');
      g_form.setValue('location',answer);
    }

 

 

Please Mark Correct answer if it help you in any way.

Thanks and Regards,

Kunal.