how to Auto populate based on logged in user

Ashok_308
Tera Contributor

I want to Auto populate Requested by, requested for ,user id ,contact number, location and email fields.

14 REPLIES 14

It would be Reference field only. 

@Ashok_308 
have you tried the above code which i have mentioned?

for populating other field values we do have new feature in variable dictionary as "dependent value" so you choose requested for all(phone , email , location details etc)

let me know if this works for you.!!


Please accept the solution /mark this response as correct or helpful if it assisted you with your question.




Regards,
Animesh

@Ashok_308 
could you close the thread/accept the solution if it helped you for solving the query or still you are facing issue then let us know.!!! 


Please accept the solution /mark this response as correct or helpful if it assisted you with your question.




Regards,
Animesh

Ajay_kumar
Tera Contributor

If you are using a Catalog Item, you can do this via an onChange Catalog Client script as below

 

onChange Catalog Client Script

 

Variable = Requested for

 

 

 

function onChange(control, oldValue, newValue, isLoading) {

if (isLoading || newValue == '') {

  return;

 

}

var ga = new GlideAjax('CheckRecords');

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

ga.addParam('sysparm_userID, newValue);

ga.getXML(updateValues);

 

function updateValues(response){

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

var parsedAnswer = JSON.parse(answer);

g_form.setValue('email', parsedAnswer.email);

g_form.setValue('employee_id', parsedAnswer.employee);

g_form.setValue('manager_name', parsedAnswer.manager);

g_form.setValue('title', parsedAnswer.title);

g_form.setValue('cost_center', parsedAnswer.costcenter);

g_form.setValue('application', parsedAnswer.application);

}

}

 

 

Script Include

 

 

 

var CheckRecords = Class.create();

CheckRecords.prototype = Object.extendsObject(AbstractAjaxProcessor, {

checkRecordPresent: function(){

var obj = {

'email': '',

'employee_id': '',

'manager_name': '',

'title': '',

'cost_center': '',

'application': ''

};

var id = this.getParameter('sysparm_userID');           

var gr = new GlideRecord('sys_user');

gr.addQuery('sys_id', id);

gr.setLimit(1);

gr.query();

if(gr.next()){

obj['email'] = gr.email;

obj['employee_id'] = gr.employee_number;

obj['manager_name'] = gr.manager;

obj['title'] = gr.title;

obj['cost_center'] = gr.cost_center;

obj['application'] = gr.application;

 }

return JSON.stringify(obj);

},

 type: 'CheckRecords'

 

});

 

 

Please mark this as helpful..

Nayum Pasha
Tera Contributor

1. if you want to auto populate field with logged in user use gs.getUser(); will return logged in User object and you do dot walking for userid, location. email, contact number. (in Dictionary default value).

2.Use on change client script and script include to auto populate on selecting any user.

Spoiler