Created
February 19, 2015 19:49
-
-
Save asimpkin/0f9daeeffdfe75677cbe to your computer and use it in GitHub Desktop.
ServiceNow Business Rule - Advanced Reference Qualifier for TASK.cmdb_ci
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
function GetCiForCMDB_CI() { | |
var a = ''; | |
if(current.u_root_cause=='3rd Party') { // restrict to 3rd party business services when root cuase is C1 Supplier | |
var gr = new GlideRecord('cmdb_ci'); | |
gr.addQuery('sys_class_name', 'u_cmdb_ci_service_3rdparty'); | |
gr.query(); | |
while (gr.next()) { | |
if (a !='') { | |
a = a + '^ORsys_id='+ gr.sys_id ; | |
} else { | |
a = 'sys_id=' + gr.sys_id ; | |
} // end if | |
} // end while | |
} else if (2==3) { | |
// next option if required.. keep building | |
} else { // no match so null var, will return all values. | |
a = ''; | |
} // end if | |
return a; | |
} // end function |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The ServiceNow task.cmdb_ci field was required to restrict data based on conditions present within the current record. As the cmdb_ci field is a reference field this advanced reference qualifier, called by script, can be used to narrow the list. This saves the analyst time by narrowing the CI list to only those records which are cmdb_ci.class == 3rd party supplier when the current.u_root_cause field is set to Supplier.
Do not even get me started on why someone felt that incidents required root cause, so consider this a filthy hack. I cannot guarantee this will work forever.
It works because current.u_root_cause value is set when the cmdb_ci reference icon is clicked or data is typed into the field which makes an ajax call to the server... client generated, which therefore will read the values of the current record. If a condition does not match then the script will return a NULL value for VAR A which lets TASK.cmdb_ci select all values. ie NO Reference Qualifier.
Tested with :: glide-eureka-04-08-2014__patch3-hotfix1-07-30-2014