Unable to retrieve additional field values from a selected Remote Table reference
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi Everyone,
I'm working on a Service Catalog item where a user selects a record from a Remote Table (using a Reference variable).
Based on the selected record, I need to retrieve another field (for example, a Description field), parse its value, and populate another catalog variable.
I have already tried:
- Changing the variable from a Lookup Select Box to a Reference.
- Dot-walking to retrieve the Description field.
- Calling a Client Callable Script Include using GlideAjax.
- Querying the Remote Table using GlideRecord with both the selected value and another unique field.
The GlideAjax call reaches the Script Include successfully, but I'm unable to retrieve the matching record from the Remote Table.
My questions are:
- Is it possible to dot-walk to fields from a Remote Table reference?
- Is GlideRecord the correct way to query a Remote Table from a Script Include?
- What is the recommended approach to retrieve additional field values from a selected Remote Table record?
Any suggestions or best practices would be appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@MaheshG95462175 Ideally, the GlideRecord call should work. Could you please share your client script and script include code to populate the data from remote table.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Script include
var EnvironmentUtil = Class.create();
EnvironmentUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getEnvironmentOwner: function() {
var groupId = this.getParameter('sysparm_group_id');
if (!groupId)
return '';
var gr = new GlideRecord('u_environment_groups');
if (!gr.get(groupId))
return '';
var desc = gr.getValue('u_description');
if (!desc)
return '';
return desc.replace('Environment Access for ', '').trim();
},
type: 'EnvironmentUtil'
});
Client script
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || !newValue)
return;
if (g_form.getValue('request_type') != 'existing_environment_access')
return;
g_form.setDisplay('group_name', true);
g_form.setMandatory('group_name', true);
g_form.setValue(
'group_name',
g_form.getDisplayValue('existing_environment')
);
g_form.setReadOnly('group_name', true);
g_form.setDisplay('environment_owner', true);
g_form.setReadOnly('environment_owner', true);
var ga = new GlideAjax('EnvironmentUtil');
ga.addParam('sysparm_name', 'getEnvironmentOwner');
ga.addParam('sysparm_group_id', newValue);
ga.getXMLAnswer(function(answer) {
if (answer) {
g_form.setValue('environment_owner', answer);
} else {
g_form.clearValue('environment_owner');
}
g_form.setReadOnly('environment_owner', true);
setTimeout(function() {
g_form.setMandatory('environment_owner', true);
}, 100);
});
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
@MaheshG95462175 Please confirm the following.
var gr = new GlideRecord('u_environment_groups');
if(!gr.get(groupId))
Since the table name starts with u_ I am assuming this is a custom table, assuming group is a field defined on this custom table. In order to get the description you are calling .get method and passing groupID as a parameter. If you call .get method with one parameter, the GlideRecord assumes it needs to search for the record in sys_id column. Since you are trying to search in the group column you should use .get slightly differently.
var gr = new GlideRecord('u_environment_groups');
if(!gr.get('u_group',groupId)) //Assuming the column which holds group is u_group.
Please make this change and see if the query returns any result. Also, in order to debug, use gs.info() across different lines in your script include to check if the query returns any result or not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 weeks ago
Try this:
1: Create a Client-Callable Script Include
- Name: RemoteTableUtils
- Client callable: Checked (True)
var RemoteTable = Class.create();
RemoteTable.prototype = Object.extendsObject(AbstractScriptProcessor, {
getRemoteDescription: function() {
var recordId = this.getParameter('sysparm_record_id');
if (!recordId) return '';
var gr = new GlideRecord('u_your_remote_table_name'); // Replace with your actual Remote Table API name
if (gr.get(recordId)) {
return gr.getValue('u_description'); // Replace with your actual Description field name
}
return '';
},
type: 'RemoteTable'
});
2: Create an onChange Catalog Client Script
- Applies to: Catalog Item
- Type: onChange
- Variable name: Select your Reference variable
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue === '') {
return;
}
var ga = new GlideAjax('RemoteTable');
ga.addParam('sysparm_name', 'getRemoteDescription');
ga.addParam('sysparm_record_id', newValue);
ga.getXMLAnswer(parseAndPopulate);
}
function parseAndPopulate(response) {
var description = response;
if (description) {
try {
var parsedData = JSON.parse(description);
g_form.setValue('your_target_variable_name', parsedData.targetValue);
} catch (e) {
if (description.indexOf('Code:') > -1) {
var extractedValue = description.split('Code:')[1].trim();
g_form.setValue('your_target_variable_name', extractedValue);
} else {
g_form.setValue('your_target_variable_name', description);
}
}
}
}
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti