Apply default value for Cascading filters
Default Value for Cascading filters
Recently, I had a challenge where I have to apply default values for Cascading filters. Unlike the interactive filters, there is no option to apply default values for this.
The cascading filter values are stored in this table - sys_canvas_preferences. First I created my preference which has to be set as the default value. A record got created in the canvas preferences table, there is a user field in the canvas record, I just updated the user value to a different user. Then I Impersonated the user and navigated to the dashboard and it worked perfectly, the cascading filter had the value populated for the user.
I used the same logic to create canvas records for few users. The values in the preference table can be pretty tricky to apply so I used the template option to create records.
I created a template [sys_template] with all the values drawn from my preference record except the user field. Finally used a simple glide record query in the background script to create records for users.
sys_template record
GlideRecord Query
var grSysUser = new GlideRecord('sys_user');
grSysUser.addEncodedQuery("department=a581ab703710200044e0bfc8bcbe5de8");//only finance dept
grSysUser.query();
while (grSysUser.next()) {
var canvas = new GlideRecord('sys_canvas_preferences'); // default filter record table
canvas.initialize();
canvas.applyTemplate("canvas template"); // created template form default value
canvas.user = grSysUser.getUniqueValue();
canvas.insert();
}
Stay safe, stay healthy!
Thanks!
Murali
https://www.servicenow.com/community/platform-analytics-articles/apply-default-value-for-cascading-filters/ta-p/2302832