Created
December 13, 2023 18:54
-
-
Save cmcdevitt/b638421dfd2fd7d8a7705d8a186f4ee3 to your computer and use it in GitHub Desktop.
Dynamic Filter Options Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Use Case: Provide an "Is Dynamic" option for the "Company" field on a Condition Builder | |
#1 | |
Client Callable Script Include | |
Global Scope, Accessable All Scopes | |
Related ACL: | |
type: client_callable_script_include | |
operation: Execute | |
name: DynamicFilters | |
Role: ITIL | |
#2 | |
Dynamic Filter Option | |
Lable: My Company | |
Script: new global.DynamicFilters().myCompany() | |
Field type: Reference | |
Reference table: Company[core_company] | |
Active: True | |
Available for filter: True | |
*/ | |
var DynamicFilters = Class.create(); | |
DynamicFilters.prototype = Object.extendsObject(AbstractAjaxProcessor, { | |
/* | |
* References | |
* https://docs.servicenow.com/bundle/vancouver-platform-user-interface/page/use/using-lists/task/t_ScriptedFilters.html | |
* https://docs.servicenow.com/bundle/vancouver-platform-user-interface/page/use/using-lists/task/t_DynamicFilterOptions.html | |
*/ | |
myCompany: function() { | |
/* | |
* This Method is intended to return the current users Company from the User Table[sys_user] | |
* argument none | |
* return an array of Company sys_id's | |
* Note: This is inteneded for use as a dynamic filter, which expects an array as input | |
*/ | |
var companies = []; | |
var current_user = gs.getUserID(); | |
var user = new GlideRecord('sys_user'); | |
user.get(current_user); | |
if(user.company){ | |
companies.push(user.company.toString()); | |
}else{ | |
//Consider returning a default company or all companies if the users does not have a company | |
} | |
gs.info("DynamicFiter called and " + companies.toString()); | |
return companies; | |
}, | |
type: 'DynamicFilters' | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment