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

Mark Roethof
Tera Patron
Tera Patron

Hi there,

See this article I wrote a few weeks ago. Contains detailed explanation and examples:
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

asifnoor
Kilo Patron

Hi,

Can you share the GlideAjax code that you have written. I can check and correct it for you.

Refer to this link for sample script include.

https://community.servicenow.com/community?id=community_article&sys_id=1acbf485db063f80fff8a345ca961...

Mark the comment as helpful if it helps.

renu8
Giga Contributor

function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
    
    var ga=new GlideAjax('AutopopulatedetailsC');
    ga.addParam('sysparm_name',setEmail);
    ga.addParam('sysparm_caller',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('email',answer);
        
    }

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

ScriptInclude:

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

    type: 'AutopopulatedetailsC'
});

Okay 2 changes.

In SI,  replace this line

return gr.email

with

return gr.getValue("email");

In the client script, replace this line

 ga.addParam('sysparm_caller',g_form.getValue('caller_id'));

with

 ga.addParam('sysparm_caller',newValue);

Kindly mark the comment as a correct answer and helpful if it helps to solve your problem.

Regards,
Asif
2020 ServiceNow Community MVP