- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2024 02:07 PM - edited 01-03-2024 02:09 PM
Good afternoon,
I'm attempting to use GlideRecord to read and display values from the current logged in user's HR Profile. I have the following in a before display business rule on the sn_hr_er_case table:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord('sn_hr_core_profile');
gr.get(gs.getUserID());
var sigName = gr.u_legal_name.getDisplayValue();
var sigTitle = gr.u_business_title.getDisplayValue();
g_scratchpad.signature = "Thank you," + "\n" + sigName + "\n" + sigTitle;
})(current, previous);
I have a simple UI Action to add the scratchpad values, but the legal name and business title fields aren't populating, only the "Thank you," text.
Is there perhaps a read/security error with attempting to GlideRecord / copy values from the sn_hr_core_profile table?
Thanks for your consideration!
Solved! Go to Solution.
- Labels:
-
Human Resources Service Delivery
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2024 03:15 PM - edited 01-03-2024 03:16 PM
The problem seems to be the use of gs.getUserID() to query the HR profile table.
gs.getUserID will give you the sys_id of the user table record which belongs to the currently logged in user.
Please try below
var grHRProfile = new GlideRecord('sn_hr_core_profile');
grHRProfile.addEncodedQuery('user.sys_id='+gs.getUserID());
grHRProfile.query(); // Query will execute the glideRecord
grHRProfile.next(); //Will allow the getDisplayValues below to work
var sigName = grHRProfile.u_legal_name.getDisplayValue();
var sigTitle = grHRProfile.u_business_title.getDisplayValue();
g_scratchpad.signature = "Thank you," + "\n" + sigName + "\n" + sigTitle;
Please mark helpful, if this helped, or accept the solution if it worked.
Thanks,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2024 07:47 PM
@lawrencemgann Please update the business rule as follows.
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideRecord('sn_hr_core_profile');
gr.addQuery('user', gs.getUserID()); //You need add filter on the user column on hr profile table
gr.query();
if (gr.next()) {
var sigName = gr.u_legal_name.getDisplayValue();
var sigTitle = gr.u_business_title.getDisplayValue();
g_scratchpad.signature = "Thank you," + "\n" + sigName + "\n" + sigTitle;
}
})(current, previous);
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2024 03:15 PM - edited 01-03-2024 03:16 PM
The problem seems to be the use of gs.getUserID() to query the HR profile table.
gs.getUserID will give you the sys_id of the user table record which belongs to the currently logged in user.
Please try below
var grHRProfile = new GlideRecord('sn_hr_core_profile');
grHRProfile.addEncodedQuery('user.sys_id='+gs.getUserID());
grHRProfile.query(); // Query will execute the glideRecord
grHRProfile.next(); //Will allow the getDisplayValues below to work
var sigName = grHRProfile.u_legal_name.getDisplayValue();
var sigTitle = grHRProfile.u_business_title.getDisplayValue();
g_scratchpad.signature = "Thank you," + "\n" + sigName + "\n" + sigTitle;
Please mark helpful, if this helped, or accept the solution if it worked.
Thanks,

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-03-2024 07:47 PM
@lawrencemgann Please update the business rule as follows.
(function executeRule(current, previous /*null when async*/ ) {
// Add your code here
var gr = new GlideRecord('sn_hr_core_profile');
gr.addQuery('user', gs.getUserID()); //You need add filter on the user column on hr profile table
gr.query();
if (gr.next()) {
var sigName = gr.u_legal_name.getDisplayValue();
var sigTitle = gr.u_business_title.getDisplayValue();
g_scratchpad.signature = "Thank you," + "\n" + sigName + "\n" + sigTitle;
}
})(current, previous);
Hope this helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2024 08:03 AM
Thank you both, these are both very helpful and well explained!