- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2019 11:28 AM
Hi there,
I'm working on a custom table with a choice field that gets its options dynamically filled by a Client Script that way:
g_form.addOption('<field>', <name of a table>, <label the table>);
When I open the dropdown, I see the labels as expected. But when I save the form, I suddenly see the name instead.
Example: I select "Story", but after saving, I see "rm_story".
Does anyone have an idea what I may be doing wrong?
Best regards,
Kosh
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-08-2019 07:15 AM
I was referring to the fact there is a Table Name field type that you can use for the field. You can then look at using an INSTACEOFtask filter to get just tables that are child of task.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2019 12:27 PM
I'm doing something similar: Using a Script Include, I am querying some tables out of sys_db_object, packing them into an array, and un-packing them in my Client Script. Then I write it into the Options with while:
function onLoad() {
try {
var teststring = new GlideAjax('VacationAssignmentTablesUtil');
teststring.addParam('sysparm_name', 'getAssignmentTableNames');
var taskTableArray = teststring.getXML(AnswerParse);
} catch (err) {
jslog('A JavaScript runtime error occurred: ' + err.message);
}
function AnswerParse(response) {
var answer = response.responseXML.documentElement.getAttribute("answer");
var assignmentTablesArray = answer.split("#");
var arrayLength = assignmentTablesArray.length;
assignmentTablesArray.forEach(splitTables);
var singleTableArray = [];
function splitTables(item, index, arr) {
singleTableArray = item.split(",");
g_form.addOption('u_assignment_table', singleTableArray[0], singleTableArray[1]);
}
}
}
Basically, it works pretty fine: All the tables are there as expected, and I can select one of them. Just when I save, the choice field shows the value (aka singleTableArray[0]) instead of the label.
So I have no choice but use the table name in both value and label?
Thanks a lot to you all for your input!
Edit: There is no dependency to other fields. I just want to get this very special choice field filled once with a list of tables that I queried before. It shall happen when the form is loaded, and it doesn't have to be changed. I somehow expected that it would easily work with addOption(). But writing directly into the choices table is something I'll have to play with. Never did that, but I'm pretty new to SNC development. 🙂

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2019 12:40 PM
Another thought would be to change the type of the field if you can to "Table" I think it is and then set a filter to only show the ones you want.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2019 12:48 PM
You mean a reference field to sys_db_object? That was my first try. Maybe I should have asked how to set a filter to a reference field through a Client Script instead because that's where I miserably failed. I would need to enforce a filter when doing the lookup, so that the field will only suggest the Task table and all of its children. If I fix such a filter on the table column, it will save the filter using the sys_id of the task table (super_class=xxxxx), but that's something I have to avoid. It destroys the portability of the application because the Task table seems to have other sys_ids in other instances.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2019 10:09 PM
Create a reference field. Refer to sys_db_object.
I assume, the values in the reference field should be filtered based on some other field value.
If yes, then write a SI which will accept the changed value as a parameter and filte the tables in sys_db_object and return the sys_ids.
Refer to this article where i have shown how you can add reference qualifiers.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎11-07-2019 11:43 PM
Awewome, that could help me further! The field is not depending on any other field, it shall just show all tables below Task + the Task table itself (in order to show all tables having the assigned_to field).
I just need to find a way to get an encoded query saying "super_class=<Task table>" without using its sys_id (or querying the Task table sys_id somehow). Maybe I can use something like "name='task'^ORsuper_class.name='task'"?
I'll try it out and give feedback later.
Thankyou so much!
Mark the comment as a correct answer and helpful once worked.