Show specific table records in Document iD field type
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-20-2025 10:58 AM
The requirement is to show active table records for a document ID field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-20-2025 01:46 PM
Query each of the tables returned by:
https://[instance].service-now.com/sys_dictionary_list.do?sysparm_query=internal_type%3Ddocument_id&sysparm_view=advanced
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-20-2025 03:01 PM
The requirement is to show only active records from the selected table in Document ID field
For Ex: I need to show only active incident records if user select incident table in Document ID field
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-21-2025 09:40 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
ā08-22-2025 09:39 AM
Document ID fields are tricky, since they depend on a reference table. and without more details on which tables and fields it hard to recommend a good solution. I did come up with a business rule for my 'test table' that has 'u_document_table' column for the reference table, and 'u_document_id' column for the Document ID field. the BR aborts the update if an in-active record is selected.
The script logic follows:
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var refTable = current.u_document_table;
// gs.info("CheckTable: reference table is: " + refTable);
// see if table is extended from task
var table = new TableUtils(refTable);
var baseTable = table.getAbsoluteBase();
if (baseTable == 'task')
refTable = 'task';
// see if the table has an 'active' field
var dict = new GlideRecord('sys_dictionary');
dict.addQuery('name', refTable);
dict.addQuery('element', 'active');
dict.query();
if (!dict.next())
return; // don't check
// gs.info("CheckTable: reference table has active field.");
var rec = new GlideRecord(refTable);
rec.addQuery('sys_id', current.u_document_id);
rec.query();
// gs.info("CheckTable: Found " + rec.getRowCount() + " records.");
if (rec.next()) {
result = rec.active;
// gs.info('CheckTable: active = '+ result);
if (!rec.active) {
gs.addInfoMessage('Record is not active');
current.setAbortAction(true);
}
}
})(current, previous);You will have to change the table, reference field and document id field names for your use-case. And there are likely better approaches depending on specific details of your use-case.
