<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>question Auto populate user details through script include and glide ajax in ITSM forum</title>
    <link>https://www.servicenow.com/community/itsm-forum/auto-populate-user-details-through-script-include-and-glide-ajax/m-p/2665826#M502486</link>
    <description>&lt;P&gt;Auto populate user details through script include and glide ajax&lt;/P&gt;</description>
    <pubDate>Fri, 08 Sep 2023 08:05:32 GMT</pubDate>
    <dc:creator>hemathsnow002</dc:creator>
    <dc:date>2023-09-08T08:05:32Z</dc:date>
    <item>
      <title>Auto populate user details through script include and glide ajax</title>
      <link>https://www.servicenow.com/community/itsm-forum/auto-populate-user-details-through-script-include-and-glide-ajax/m-p/2665826#M502486</link>
      <description>&lt;P&gt;Auto populate user details through script include and glide ajax&lt;/P&gt;</description>
      <pubDate>Fri, 08 Sep 2023 08:05:32 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/auto-populate-user-details-through-script-include-and-glide-ajax/m-p/2665826#M502486</guid>
      <dc:creator>hemathsnow002</dc:creator>
      <dc:date>2023-09-08T08:05:32Z</dc:date>
    </item>
    <item>
      <title>Re: Auto populate user details through script include and glide ajax</title>
      <link>https://www.servicenow.com/community/itsm-forum/auto-populate-user-details-through-script-include-and-glide-ajax/m-p/2666336#M502529</link>
      <description>&lt;P&gt;Hello&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/597644"&gt;@hemathsnow002&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Please refer the below link.&lt;/P&gt;
&lt;P&gt;&lt;A href="https://www.servicenow.com/community/developer-articles/auto-populate-user-details-using-ajax/ta-p/2315390" target="_self"&gt;https://www.servicenow.com/community/developer-articles/auto-populate-user-details-using-ajax/ta-p/2315390&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Regards,&lt;/P&gt;
&lt;P&gt;Namrata&lt;/P&gt;</description>
      <pubDate>Fri, 08 Sep 2023 15:49:28 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/auto-populate-user-details-through-script-include-and-glide-ajax/m-p/2666336#M502529</guid>
      <dc:creator>Community Alums</dc:creator>
      <dc:date>2023-09-08T15:49:28Z</dc:date>
    </item>
    <item>
      <title>Re: Auto populate user details through script include and glide ajax</title>
      <link>https://www.servicenow.com/community/itsm-forum/auto-populate-user-details-through-script-include-and-glide-ajax/m-p/2666347#M502530</link>
      <description>&lt;P&gt;Hi there,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Here you go:&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;- 2020-01-10 - Article -&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://community.servicenow.com/community?id=community_article&amp;amp;sys_id=c918c3b8db968c5013b5fb2439961918" target="_blank" rel="noopener noreferrer"&gt;Client Side Scripting: Go for GlideAjax (with getXMLAnswer)!&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Sep 2023 15:57:10 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/auto-populate-user-details-through-script-include-and-glide-ajax/m-p/2666347#M502530</guid>
      <dc:creator>Mark Roethof</dc:creator>
      <dc:date>2023-09-08T15:57:10Z</dc:date>
    </item>
    <item>
      <title>Re: Auto populate user details through script include and glide ajax</title>
      <link>https://www.servicenow.com/community/itsm-forum/auto-populate-user-details-through-script-include-and-glide-ajax/m-p/2666471#M502537</link>
      <description>&lt;P&gt;Refer below code and change it as per your need, Make sure you mark client callable true on script include&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Client script:&lt;/P&gt;&lt;DIV&gt;function onChange(control, oldValue, newValue, isLoading, isTemplate) {&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;if (isLoading || newValue === '') {&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; return;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;}&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;var ga = new GlideAjax("userDetailsUtil");// Script include name&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; ga.addParam('sysparm_name', 'getUserDetails');//Script include function name&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; ga.addParam('sysparm_usersysid', newValue);// newValue object in onchange client script always return changed value of the field&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; ga.getXML(getDetails);//Calling call back function to convert response and set values&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; function getDetails(response) {//call back function&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var answer = response.responseXML.documentElement.getAttribute("answer");&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; var objval = JSON.parse(answer);&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;g_form.setValue("u_department",objval.department);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; alert(objval.department);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;}&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Script include:&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;var userDetailsUtil = Class.create();&lt;/DIV&gt;&lt;DIV&gt;userDetailsUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {&lt;/DIV&gt;&lt;DIV&gt;getUserDetails:function(){//Function declaration&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var obj = {};//json to collect the information&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;&amp;nbsp; var usersysid = this.getParameter('sysparm_usersysid');&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var gr=new GlideRecord('sys_user');//glide user table&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;gr.get(usersysid);&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;obj.email=gr.getValue('email');//map values&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;obj.department=gr.getValue('department');&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;var json = new JSON();&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; return json.encode(obj);&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;},&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp; &amp;nbsp; type: 'userDetailsUtil'&lt;/DIV&gt;&lt;DIV&gt;});&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Fri, 08 Sep 2023 18:36:59 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/auto-populate-user-details-through-script-include-and-glide-ajax/m-p/2666471#M502537</guid>
      <dc:creator>Raghu3</dc:creator>
      <dc:date>2023-09-08T18:36:59Z</dc:date>
    </item>
    <item>
      <title>Re: Auto populate user details through script include and glide ajax</title>
      <link>https://www.servicenow.com/community/itsm-forum/auto-populate-user-details-through-script-include-and-glide-ajax/m-p/2666562#M502540</link>
      <description>&lt;P&gt;Is it for catalog item variables? or is it for form in Core UI?&lt;/P&gt;&lt;P&gt;If it's for catalog item variables, then why use scripts? Instead, use 'Service catalog data lookup'&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.servicenow.com/en-US/bundle/vancouver-servicenow-platform/page/product/service-catalog-management/concept/c_ServiceCatalogDataLookup.html" target="_blank"&gt;https://docs.servicenow.com/en-US/bundle/vancouver-servicenow-platform/page/product/service-catalog-management/concept/c_ServiceCatalogDataLookup.html&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 08 Sep 2023 21:50:25 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/auto-populate-user-details-through-script-include-and-glide-ajax/m-p/2666562#M502540</guid>
      <dc:creator>maroon_byte</dc:creator>
      <dc:date>2023-09-08T21:50:25Z</dc:date>
    </item>
    <item>
      <title>Re: Auto populate user details through script include and glide ajax</title>
      <link>https://www.servicenow.com/community/itsm-forum/auto-populate-user-details-through-script-include-and-glide-ajax/m-p/2666678#M502544</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://www.servicenow.com/community/user/viewprofilepage/user-id/597644"&gt;@hemathsnow002&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;We can take a simple scenario here- based on the user selected on the form level, we need to auto populate the user's email ID.&lt;/P&gt;&lt;P&gt;User - form variable name is - form_user&lt;/P&gt;&lt;P&gt;Email -&amp;nbsp;form variable name is - form_email&lt;/P&gt;&lt;P&gt;Script Include -&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;var populateemail = Class.create();
populateemail.prototype = Object.extendsObject(AbstractAjaxProcessor, {
    getemail: function() {
        var sysid = this.getParameter('sysparm_username');
        var gr = new GlideRecord('sys_user');
        gr.addQuery('sys_id', sysid);
        gr.query();
        if (gr.next()) {
            var ans = gr.email;
            return ans;
        }
    },
    type: 'populateemail'
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Client Script-&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function onChange(control, oldValue, newValue, isLoading) {
   if (isLoading || newValue == '') {
      return;
   }
   var ga = new GlideAjax('populateemail');
    ga.addParam('sysparm_name', 'getemail');
    var usersysid = g_form.getValue('form_user');
    ga.addParam('sysparm_username', usersysid);
    ga.getXML(callBackFunction);

    function callBackFunction(response) {
        var answer = response.responseXML.documentElement.getAttribute("answer");
		g_form.setValue('form_email', answer);
    }  
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;There is another way where we don't use script include, you can directly write on-change client script on user variable.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function onChange(control, oldValue, newValue, isLoading) {
    if (isLoading || newValue == '') {
        return;
    }
 var cmp = g_form.getReference('form_user', mycallback);
  function mycallback(cmp) {
        g_form.setValue('form_email', cmp.email);
}
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Mark this answer as correct and helpful if it solves your issue.&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Regards,&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;Siva Jyothi M.&lt;/STRONG&gt;&lt;/P&gt;</description>
      <pubDate>Sat, 09 Sep 2023 08:42:18 GMT</pubDate>
      <guid>https://www.servicenow.com/community/itsm-forum/auto-populate-user-details-through-script-include-and-glide-ajax/m-p/2666678#M502544</guid>
      <dc:creator>Siva Jyothi M</dc:creator>
      <dc:date>2023-09-09T08:42:18Z</dc:date>
    </item>
  </channel>
</rss>

