The CreatorCon Call for Content is officially open! Get started here.

how to populate user phone number and Email-ID and Group manager name on incident form ?

ram2497
Tera Contributor

how to populate user phone number and Email-ID and Group manager name on incident form  ?

1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron

i am just adding a sample script to populated user information using the script include. same way you can try to get the group manager.

 

Create a Client Callable Script include :-

 

var GetUserDetailsAjax = Class.create();
GetUserDetailsAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getInfo: function(){


   var obj={};
  
   obj.email='';
   obj.phone='';
  
   var id=this.getParameter('sysparm_user_id');
   var gr= new GlideRecord('sys_user');
   if(gr.get(id)){
   obj.phone=gr.phone.toString();
   obj.email=gr.email.toString();

   }


   return JSON.stringify(obj);


   },
    
    type: 'GetUserDetailsAjax'
});

 


 

onChange Client Script :-

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
    
    var id = g_form.getValue('<user field>');

   var ga = new GlideAjax('GetUserDetailsAjax');

   ga.addParam('sysparm_name','getInfo');

   ga.addParam('sysparm_user_id',id);

   ga.getXML(CallBack);



   function CallBack(response)
    {


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


   var user=JSON.parse(answer);


   g_form.setValue('req_email', user.email); // set the value based on your field


   g_form.setValue('req_phone', user.phone); // set the value based on your field


   }

   
}

same concept you can apply to get the group manager name 'based on your group.

 

give a try and let us know if you need any further help.

 

View solution in original post

3 REPLIES 3

Alikutty A
Tera Sage

You can either configure the form layout and add these fields on the Form. User.Email, User.Phone Number and Assignment Group.Manager. All of these should be dot walked and added on form.

Or else you need to write a client script or business rule to populate these values which would involve scripting.

Thanks!

Harsh Vardhan
Giga Patron

i am just adding a sample script to populated user information using the script include. same way you can try to get the group manager.

 

Create a Client Callable Script include :-

 

var GetUserDetailsAjax = Class.create();
GetUserDetailsAjax.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getInfo: function(){


   var obj={};
  
   obj.email='';
   obj.phone='';
  
   var id=this.getParameter('sysparm_user_id');
   var gr= new GlideRecord('sys_user');
   if(gr.get(id)){
   obj.phone=gr.phone.toString();
   obj.email=gr.email.toString();

   }


   return JSON.stringify(obj);


   },
    
    type: 'GetUserDetailsAjax'
});

 


 

onChange Client Script :-

 

function onChange(control, oldValue, newValue, isLoading, isTemplate) {
   if (isLoading || newValue === '') {
      return;
   }
    
    var id = g_form.getValue('<user field>');

   var ga = new GlideAjax('GetUserDetailsAjax');

   ga.addParam('sysparm_name','getInfo');

   ga.addParam('sysparm_user_id',id);

   ga.getXML(CallBack);



   function CallBack(response)
    {


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


   var user=JSON.parse(answer);


   g_form.setValue('req_email', user.email); // set the value based on your field


   g_form.setValue('req_phone', user.phone); // set the value based on your field


   }

   
}

same concept you can apply to get the group manager name 'based on your group.

 

give a try and let us know if you need any further help.

 

Harsh Vardhan
Giga Patron

it's duplicate thread, please follow on one thread so it would be easy to follow up on your questions.

i had answered the same query on below thread.

https://community.servicenow.com/community?id=community_question&sys_id=101f9570db1ae70011762183ca96...