field not populated in ESC view
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2024 05:31 AM
function onChange(control, oldValue, newValue, isLoading) {
// Prevent the script from running if the form is loading or the new value is empty
if (isLoading || newValue === '') {
return;
}
// Get the sys_id from the 'sysid' field
var memberSysID = newValue;
// Create a GlideRecord object for the 'sys_user_grmember' table
var grMember = new GlideRecord('sys_user_grmember');
if (grMember.get(memberSysID)) {
// If the record is found, retrieve the 'group' sys_id from the member record
var groupSysID = grMember.getValue('group');
// Create another GlideRecord object for the 'sys_user_group' table
var grGroup = new GlideRecord('sys_user_group');
if (grGroup.get(groupSysID)) {
// Retrieve the 'name' property from the group record
var groupName = grGroup.getValue('name');
// Set the value of the 'group_sysid' field
g_form.setValue('group_sysid', groupName);
} else {
// Clear the 'group_sysid' field if no group record is found
g_form.setValue('group_sysid', '');
}
} else {
// Clear the 'group_sysid' field if no member record is found
g_form.setValue('group_sysid', '');
}
}
The following script is supposed to retrieve the sysID field value and then query groups table to retrieve the name of the table:
it works on the backend, but when i test it in ESC this field is not getting populated:
any ideas why?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2024 07:27 AM
@dev_K Could you please share the code of your client script and script include. Need to check if it is syntactically correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2024 07:31 AM
I just copy pasted the client script and script include you provided. Basically want I want is to take the sysId available in the 'sysid' field and query table sys_user_grmember for this record to retrieve 'group' property'. This should return a sysID that I want to populate 'group_sysid' field with. It worked with using GlideRecord on the backend only...

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2024 07:40 AM
@dev_K Please see if the following change works for you.
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return; // Don't run the script if the form is loading or the new value is empty
}
// Create a new GlideAjax object, calling the server-side script include 'GetGroupByMember'
var ga = new GlideAjax('GetGroupByMember');
// Add the member sys_id (newValue) as a parameter
ga.addParam('sysparm_sys_id', newValue);
// Make the asynchronous call to the Script Include
ga.getXMLAnswer(getGroupByMember);
function getGroupByMember(response){
var groupSysId = response.responseXML.documentElement.getAttribute("answer");
if (groupSysId) {
console.log('Group Sys ID: ' + groupSysId);
g_form.setValue('group_sysid',groupSysId );
// Perform any additional actions like populating a field with the group sys_id
} else {
console.log('No group found for this member.');
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2024 07:45 AM
I copied exactly the same code and i got these console error messages:
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-30-2024 07:46 AM