Populate Employee details based on Employee id
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2022 11:12 PM
Hi All,
I have a custom table. In which I have created a field called Employee name which is referring to sys_user table and from user table I have called other fields using dot walk as Employee Number, Country, LOcation which is auto populating from user profile
But now client want user should enter employee id then other fields should be auto populated. I have written below BR on that custom table (sn_hr_core_id):
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord("sys_user");
gr.addQuery('employee_number' , current.u_employee_name.employee_number);
gr.query();
while(gr.next()){
gs.addInfoMessage("1");
current.u_employee_name = gr.name.toString();
current.update();
}
})(current, previous);
but not working. Any suggestion please?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2022 10:41 PM
Hmm, what if I make Employee number a custom field and then map it in transform map?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2022 11:05 PM
that should work then but please discuss with your business team about this.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-12-2022 11:56 PM
Yes, they want as this only cz they have provided Employee id only.
I have created after/update BR:
(function executeRule(current, previous /*null when async*/ ) { // Add your code here
var gr = new GlideRecord("sys_user");
gr.addQuery('employee_number', current.u_employee_id);
gr.query();
if (gr.next()) {
// gs.addInfoMessage("1");
current.u_employee_name = gr.name.toString();
current.country = gr.country;
current.location = gr.location.toString();
current.update();
}
})(current, previous);
When user create record on table by clicking New button, and enter EMployee id then all other values are getting populated as per user profile.
But while loading data it is not loading correct data when mapped with Employee id. All user's detail is empty.
Please suggest why so?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2022 11:33 PM
Hi, Try below code
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord("sys_user");
gr.addQuery('employee_number' , current.employee_number);
gr.query();
while(gr.next()){
gs.addInfoMessage("1");
current.u_employee_name = gr.name.toString();
current.update();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-11-2022 11:35 PM
Hi,
Are you getting any error or what..?