how to Auto populate based on logged in user
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-28-2024 03:23 AM
I want to Auto populate Requested by, requested for ,user id ,contact number, location and email fields.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 06:29 AM
It would be Reference field only.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-30-2024 12:52 AM
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-07-2024 04:47 AM
@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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 05:54 AM
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..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-29-2024 06:17 AM
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.