Skip to content

Instantly share code, notes, and snippets.

@cmcdevitt
Created December 13, 2023 18:54
Show Gist options
  • Save cmcdevitt/b638421dfd2fd7d8a7705d8a186f4ee3 to your computer and use it in GitHub Desktop.
Save cmcdevitt/b638421dfd2fd7d8a7705d8a186f4ee3 to your computer and use it in GitHub Desktop.
Dynamic Filter Options Example
/*
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