- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 09:56 PM - edited 03-19-2025 10:11 PM
Hi All,
Hope you are doing well,
Description:
I have created a Record Producer and need help dynamically populating a dropdown field based on the selected table.
Variables in the Record Producer:
Table Name (Variable Name: table_name)
- Type: Reference
- Reference: sys_db_object (Tables)
- Only specific tables should be visible its working.
Condition Fields (Variable Name: condition_fields)
- Type: Select Box
- Requirement:
- When a user selects a table from the Table Name dropdown, the Condition Fields dropdown should dynamically populate the fields of the selected table.
- This should happen using an onChange Client Script.
IMP: one more thing this is done in other scope not in global scope
Thanks in advance
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2025 10:18 PM
Hi @TEJAS ,
- Create an onChange Client Script on master table -
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
//Type appropriate comment here, and begin script below
var table = g_form.getReference('master_table');
var ga = new GlideAjax('ClientSideCall');
ga.addParam('sysparm_name', 'getFieldName');
ga.addParam('sysparm_tableName',table.name);
ga.getXML(getFields);
function getFields(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
alert(answer);
var fields = answer.split(',');
for (var i = 0; i < fields.length; i++) {
g_form.addOption('select_fields', i, fields[i]);
}
}
}
- Create a Glide AJAX enabled script include -
var ClientSideCall = Class.create();
ClientSideCall.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getFieldName: function() {
var fields = [];
var tableName = this.getParameter('sysparm_tableName');
gs.log("Hi "+JSON.stringify(tableName));
var getFieldNames = new GlideRecord('sys_dictionary');
getFieldNames.addQuery('name', tableName);
getFieldNames.query();
while (getFieldNames.next()) {
fields.push(getFieldNames.getValue('column_label'));
}
gs.log("Hi "+fields);
fields = fields.join(',');
return fields;
},
type: 'ClientSideCall'
});
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2025 07:02 PM
Hii @TEJAS ,
In the line var val=g_form.getReference('table_name');
In this line you have given capital but mostly backend value is not starts with capital letters
So could you please check it once by changing the correct backend value for variable table name there
And also please post the images of the entire script with conditions also
The error here coming is due to the mistake of backend value or else you didn't give any value to the table name field in the form
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-20-2025 10:52 PM
Hii @TEJAS ,
In the var val=g_form.getReference('Table_Name'); In this you have to give the backend variable name In catalog variables backend variable names not start with capital letter so table_name is correct name
Message executing script undefined ->This error coming means script working it's not the error I have add a line is it taking the table name or not Here undefined means value was not taken variable backend name is not correct could you please check it once.