reference only particular records on requester for field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2024 04:09 AM - edited 09-30-2024 04:24 AM
Hello everyone,
I have a requirement, I have a field executive assistant on HR profile.
I have a record producer which has opened for field with type as Requested for
I want to populate the value of Executive assistant on that opened for drop down, so that if logged in user opens the record producer, it shows the value of Executive assitant in the opened for drop down.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2024 05:18 AM
@Snow-Man I am assuming, you would like to populate the Executive Assistance field which is available on the HR Profile record of the logged in user as a Requested for.
If this assumption is correct and if there are no other dependent questions then I recommend you to use a combination of GlideAjax and a server side script include to fetch the value for Requested/Opened for field.
Here is an example of the onLoad script for your record producer.
Please create the client script in sn_hr_core_scope.
// Client Script - onLoad
function onLoad() {
// Get the user ID of the logged-in user
var userID = g_user.userID;
// Create a new GlideAjax object, calling the server-side script include 'GetExecutiveAssistant'
var ga = new GlideAjax('sn_hr_core.GetExecutiveAssistant');
// Add the user ID as a parameter
ga.addParam('sysparm_sys_id', userID);
// Make the asynchronous call to the Script Include
ga.getXMLAnswer(function(response) {
var executiveAssistantSysId = response.responseXML.documentElement.getAttribute("answer");
if (executiveAssistantSysId) {
console.log('Executive Assistant Sys ID: ' + executiveAssistantSysId);
// You can perform additional actions with the sys_id here, like populating fields
g_form.setValue('requested_for',executiveAssistantSysId);
} else {
console.log('No Executive Assistant found for the logged-in user.');
}
});
}
Script Include: Make sure to create the script include in sn_hr_core scope.
// Script Include - GetExecutiveAssistant
var GetExecutiveAssistant = Class.create();
GetExecutiveAssistant.prototype = Object.extendsObject(AbstractAjaxProcessor, {
// This method will be called by the client-side GlideAjax call
getExecutiveAssistant: function() {
// Get the user sys_id from the client script
var userSysId = this.getParameter('sysparm_sys_id');
// Query the HR Profile table (sn_hr_core_profile) to find the Executive Assistant for this user
var hrProfileGR = new GlideRecord('sn_hr_core_profile');
hrProfileGR.addQuery('user', userSysId); // Assuming 'user' is the reference to the logged-in user
hrProfileGR.query();
if (hrProfileGR.next()) {
// Check if the 'Executive Assistant' field is populated
if (!gs.nil(hrProfileGR.u_executive_assistant)) { //Update the field name which reflects your field.
return hrProfileGR.u_executive_assistant.toString(); // Return the sys_id of the Executive Assistant
}
}
// If no record found or no Executive Assistant, return an empty string
return '';
}
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2024 04:27 AM
Hi @Snow-Man ,
You can achieve this requirement by writing a Onload() Client Script:
- OnLoad() Client Script:
function onLoad() {
var executiveAssistant = g_user.executive_assistant;
g_form.setValue('opened_for', executiveAssistant);
}
===================================***************=========================================
"If you found my answer helpful, please give it a like and mark it as the accepted solution. It helps others find the solution more easily and supports the community!"
Thanks & Regards,
Aditya
=====================================***********==========================================

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2024 04:28 AM
@Snow-Man Following are the ways using which you can populate this field.
1. getReference: Using g_form.getReference you can fetch the value for Executive assistant field and populate it on the opened for
2. Using GlideAjax: A combination of GlideAjax+server side script include call can be made to fetch the value of Executive assistant and populate it on opened for using onChange client script
3. Auto Populate: Use auto-populate tab available on the Variable form ticles/auto-populate-a-variable-based-on-a-reference-type-variable-utah/ta-p/2475511
Hope this helps.