Retrieving field types using script include and client script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-19-2022 11:40 PM
Hi Community,
We have created multiple custom tables with multiple different fields. Most of the field type is a decimal type of field. What I want to achieve is to retrieve all those decimal field types in different custom tables that we have created [x_custom_table_1, x_custom_table_2, x_custom_table_3, x_custom_table_4]
Does anyone have sample script include to do the retrieval that will send back the array? Then sample onload client script calling the script include that will check the current form is of table that starts with 'x_custom_table'?
Regards,
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-21-2022 05:18 AM
Hi Ramel,
>Does anyone have sample script include to do the retrieval that will send back the array?
Following script will retrieve all column names of type "Decimal" in a specified table.
Script Include
var SampleUtil = Class.create();
SampleUtil.prototype = Object.extendsObject(AbstractAjaxProcessor, {
getTablesWithDecimal: function() {
var columnList = [];
var tableList = ['x_custom_table_1', 'x_custom_table_2', 'x_custom_table_3', 'x_custom_table_4'];
var gr = new GlideRecord('sys_dictionary');
gr.addEncodedQuery('GOTOinternal_type.label=Decimal^nameIN' + tableList.join(','));
//gr.setLimit(10);
gr.query();
while (gr.next()) {
columnList.push(gr.element.toString());
}
return columnList.join(',');
},
type: 'SampleUtil'
});
>Then sample onload client script calling the script include that will check the current form is of table that starts with 'x_custom_table'?
Not sure what this is suppose to mean. Script Include is only return column names. What is the relationship with an array of column names with checking if the form is of table that starts with 'x_custom_table'?
Following client script will list all the column names in a multiline text field named "field1".
function onLoad() {
var ajax = new GlideAjax('SampleUtil');
ajax.addParam('sysparm_name', 'getTablesWithDecimal');
ajax.getXMLAnswer(function(answer) {
if (answer.length > 0) {
var columnNames = answer.split(',');
columnNames = columnNames.join('\n');
g_form.setValue('field1', columnNames);
}
});
}