Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to filter the record in a document_id type field

anayna
Tera Contributor

I have a table having two fields one is a Documen ID type field called document and it has dependent value as related table .Second field  related table is a choice list having multiple choices of tables .So when the user clicks on the related table and selects a table called incident then in the document field search only the active incidents in the descending order should be visible.

 

how and where should i write my code. Currently i was writing in the calculated section of the field but it is not filtering the records can someone suggest:

 

if (current.related_table == 'incident') {
// var dependentField = current.document;
var gr = new GlideRecord('incident');
gr.addQuery('active=true');
gr.query();
var dependentFieldOptions = [];
while (gr.next()) {
dependentFieldOptions.push(gr.getValue('sys_id') + '');
}
current.variable_name = dependentFieldOptions.join(',');
}

4 REPLIES 4

BharathChintala
Mega Sage

@anayna  Document field should be reference to Task table

 

in reference qualifier give like this

active=true^sys_class_name = current.choicefieldname;

If my inputs have helped with your question, please mark my answer as accepted solution, and give a thumb up.
Bharath Chintala

Hi the document field has a dependent field called related table which is a choice type field and when the user selects the related table as incident then in the document field the incident comes in table name and now i wish to search only the active incidnet from newest to oldest so is it possible to do in the calculated section of the document id field

anayna
Tera Contributor

anayna_0-1677852814095.png

something like this ? but it is not filtering

Community Alums
Not applicable