Issue with Dynamic Filter Option

ArpitB207098286
Tera Contributor

Hi All,

I have a dynamic filter option having a script include (attached image).

It's a simple script returning a list of configuration sys_id's, but it's giving the empty list.

What am I missing here?

5 REPLIES 5

Tanushree Maiti
Tera Patron

Hi @ArpitB207098286 

 

1. For many dynamic filter configurations, the Script Include must be marked as Client Callable to be accessible by the filter engine . You ensure the same.

2. call 

From: new global. SoxUtils().getSoxRelatedCis()

To: (new SoxUtils()).getSoxRelatedCis()

Refer:https://www.servicenow.com/community/developer-forum/why-is-my-dynamic-filter-returning-empty/m-p/13...

 

3.  In script include ,

instead of

return  'sys_idIN' + unique.join(',');    

Use 

return unique.toString()

 

And then call by  new global. SoxUtils().getSoxRelatedCis()

 

Refer:https://www.servicenow.com/community/developer-forum/dynamic-filter-option-returning-empty-value/m-p...

 

4. Line 33 , I have never tried, just before ,after put log and check what your getting.

 

Please Accept the solution if it assisted you with your question & Mark this response as Helpful.
Regards
Tanushree Maiti
ServiceNow Technical Architect
LinkedIn: https://www.linkedin.com/in/tanushreemaiti

Hi Tanushree,

I have implemented their changes, still not working.

MariusAlinPopa
Tera Contributor

Hi @ArpitB207098286 ,

 

Make sure to set "Sandbox enabled" to TRUE on your script include.

Test it from a background script first to make sure the sys_id's are being returned correctly from the script include.

 

Also, as @Tanushree Maiti mentioned, remove the 'sys_idIN' part when returning from script include.

 

Let me know if this works,

Marius

Vishal Jaswal
Tera Sage

Hello @ArpitB207098286 

Script Include:

var SoxUtils = Class.create();
SoxUtils.prototype = {
    initialize: function() {},

    getSoxRelatedCIs: function() {
        var result = [];

        var sox = new GlideRecord('cmdb_ci');
        sox.addQuery('name', 'SOX - Sarbanes-Oxley');
        sox.query();

        if (sox.next()) {
            var rel = new GlideRecord('cmdb_rel_ci');
            rel.addQuery('child', sox.sys_id);
            rel.query();

            while (rel.next()) {
                var parentId = rel.parent.toString();
                if (result.indexOf(parentId) === -1) {
                    result.push(parentId);
                }
            }
        }

        return result;
    },

    type: 'SoxUtils'
};


Dynamic Filter Options:

VishalJaswal_0-1780088236901.png


Validation Results:

Configuration Item:

VishalJaswal_2-1780088286897.png

 

CI Relationships:

VishalJaswal_1-1780088265299.png
Incident List View:

VishalJaswal_3-1780088324037.png

 

Background Script: Always recommened to validate code in background script first and then use it later in actual server-side or client-side script.

VishalJaswal_0-1780088411121.png

 


Hope that helps!