Skip to content

Instantly share code, notes, and snippets.

@wave-inguane
Last active August 25, 2022 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wave-inguane/0cf83361e1cd1d1c81c99bb2e480c926 to your computer and use it in GitHub Desktop.
Save wave-inguane/0cf83361e1cd1d1c81c99bb2e480c926 to your computer and use it in GitHub Desktop.
AdminTools
var userArticleMap = new function() {
this._map = {};
this.put = function(key, val) {
if (!this.containsKey(key)) {
this._map[key] = [];
this._map[key].push(val);
} else if (this._map[key].indexOf(val) == -1) {
this._map[key].push(val);
}
};
this.containsKey = function (key) {
return this._map.hasOwnProperty(key);
};
this.get = function(key) {
return this.containsKey(key) ? this._map[key] : null;
};
this.keys = function() {
var keys = [];
for (var key in this._map) {
if (this._map.hasOwnProperty(key)) {
keys.push(key);
}
}
return keys;
};
};
//=============================================================================================
// Usage
//=============================================================================================
userArticleMap.put(gr.author+'', gr.getUniqueValue());
userArticleMap.put(gr.revised_by+'', gr.getUniqueValue());
userArticleMap.put(gr.kb_knowledge_base.owner, gr.getUniqueValue());
var kbManagersList = kbManagers.split(',');
kbManagersList.map(function(kbmanager) {
userArticleMap.put(kbmanager+'', gr.getUniqueValue());
});
var users = userArticleMap.keys();
users.map(function(user) {
var articleList = userArticleMap.get(user);
articleCount = articleList.length;
articleList= articleList.slice(0, maxArticleCount);
var inputParam = { articleList: articleList, articleCount: articleCount, isVersioningEnabled: isVersioningEnabled, isAOGEnabled: isAOGEnabled };
gs.eventQueue("epa.kb.article.expiry.warning", null, user, JSON.stringify(inputParam));
});
=====================================================================================================================
Pre Clone: Check List
=====================================================================================================================
NOTE: Clones will read exclude/preserver lists from the [source instance] that is production.
Default Clone Settings
1- Exclude tables specified in Exclusion List = [True]
Exclude large attachments data = [True]
Exclude audit and log data = [True]
1. Custom URL
2. Users
3. MID Server
4.Transform Maps
5.REST API
6.LDAP
....................................................................................................................
Scenario #3:
Table Exclusion: None [clone_data_exclude.list]
Data Preserver: Yes, plus 'Conditions' field contains a value. [clone_data_preserver.list]
Results #3:
Records in sys_temp table on target, found by Data Preserver, are preserved.
Records in sys_temp table on target, not found by Data Preserver, are deleted.
Records in sys_temp table on source, which do not exist in sys_temp table on target (based on sys_id), are copied to
sys_temp table on target.
....................................................................................................................
0. Users
[sys_user]
-Mid server users
-Local users
-Integration Users
....................................DO NOT OVERRIDE......................................................
Scenario #4:
Table Exclusion: Yes [clone_data_exclude.list]
Data Preserver: Yes, plus 'Conditions' field is empty. [clone_data_preserver.list]
Results #4:
All records in sys_temp table on target are preserved.
No records are copied over from sys_temp table on source.
..........................................................................................................
Use this setting for the following tables
1.Custom URL
[custom_url]
3.MID Server
[ecc_agent]
4.Transform Maps
[sys_transform_map]
5.REST API
[sys_rest_message]
6.LDAP
[ldap_server_config]
7. Make sure that the inbound and outbound email are inactive

Use Case or User Story

  Stories have three components,
1. a short description, which provides a way to identify the story;
2. a description, which should be written in a particular format to encapsulate the maximum level of detail
   and ensure the configuration is as accurate as possible.
   The description itself is made up of a sentence or two which will
   include terms to describe the
   --user role,
   --the activity being undertaken by that user role,
   --and the business value that will come from the activity.
You can easily remember this by writing each story to describe the who, the what, and the why. And last,
3. an acceptance criteria, which defines how we will know when the
   implementation on this story is done.


Story: 
What: < need to be done >                            -goal -> extract the location ex: application name, portal , page , widget, catalog, category, catalog item, etc.
Who   < will use >                  user or group    -goal -> extract uer roles or groups   ACLs
Why:  < business value >                             -goal -> explore the alternatives "Best Practice"
Development Focus
===============================================================================================
BEGIN - 
================================================================================================
0. ACCESS
1. CONFIGURE
sys_ui_bookmark_group.list
   q
PortalUtil:760d690a2f7a78100cc754492799b619
AdminUtil: 5c8e698a2f7a78100cc754492799b6ce
ReportUtil:362e694a2f7a78100cc754492799b6a9
2. BUILD - Dev
       
  I. [Foundation] User story
Business Objects
 2. [Crawl] Groom
  II. Implementation User role ( Who ? )
  III. Activity being undertaken by that user ( What ? )
  IV. Business value that will come from the activity ( Optional ) ( Why ? )
  
3. SCRIPT
  V. [Walk] Implement
  VI. [Run] Demo - Peer review : GOAL FOCUSED:
  VII. [Fly] Deploy
4. INTEGRATE
5. DEMO-TO-PRODUCT OWNER
  -GOAL FOCUSED : 
6. DELIVER
   -Deployment Instruction
7. USE
8. ADMINISTER
9. CUSTOMER SUPPORT
   -Ops 
===============================================================================================
END - 
================================================================================================
................................................................................................
QUERY OPERATORS
................................................................................................
=
!=
IN
NOT IN
STARTSWITH
ENDSWITH
CONTAINS
DOES NOT CONTAIN
INSTANCEOF
//Incident : onLoad : IncidentSetReadOnly
function onLoad() {
var current_state = g_form.getValue("state");
if(current_state == 7 || current_state == 8){
var ga = new GlideAjax('GetFormFields');
ga.addParam('sysparm_name', 'myVariables');
ga.addParam('sysparm_mysys_id', g_form.getUniqueValue()); //parameter
ga.getXML(ajaxResponse);
}
function ajaxResponse(serverResponse) {
// get favorite elements
var favorites = serverResponse.responseXML.getElementsByTagName("favoriteTag");
for (var i = 0; i < favorites.length; i++) {
var name = favorites[i].getAttribute("name");
var value = favorites[i].getAttribute("value");
g_form.setReadOnly(name,true);
}
}
}
//Script Include : client callable : GetFormFields
var GetFormFields = Class.create();
GetFormFields.prototype = Object.extendsObject(AbstractAjaxProcessor, {
myVariables: function() {
var sysID = this.getParameter('sysparm_mysys_id')+"";
var grINC = new GlideRecord('incident');
grINC.setLimit(1);
grINC.query();
grINC.next();
// build new response xml element for result
var result = this.newItem("resultTag");
result.setAttribute("message", "returning all favorites");
var fields = grINC.getFields(); // return java ArrayList
for (var i = 0; i < fields.size(); i++) {
var field = fields.get(i);
var name = field.getName();
var value = field.getDisplayValue();
//gs.addInfoMessage(i + ". " + name + "=" + value);
this._addFavorite(name,value);
}
},
_addFavorite: function (name, value) {
var favs = this.newItem("favoriteTag");
favs.setAttribute("name", name);
favs.setAttribute("value", value);
},
type: 'GetFormFields'
});
........................................................................................................................
File Loader
........................................................................................................................
https://dev81532.service-now.com/nav_to.do?uri=%2Fincident.do%3Fsys_id%3D5a9f7e632fa6f4100cc754492799b684%26sysparm_view%3D%26sysparm_domain%3D09ff3d105f231000b12e3572f2b4775d%26sysparm_domain_scope%3Drecord
https://dev81532.service-now.com/nav_to.do?uri=%2Fincident.do%3Fsys_id%3D5a9f7e632fa6f4100cc754492799b684%26sysparm_view%3D%26sysparm_domain%3D09ff3d105f231000b12e3572f2b4775d%26sysparm_domain_scope%3Drecord
........................................................................................................................
Scriptless : Scheduled Job
........................................................................................................................
https://dev81532.service-now.com/nav_to.do?uri=%2F$pa_dashboard.do%3Fsysparm_dashboard%3Dcc9a9ddf2f2e34100cc754492799b667%26sysparm_tab%3D46ca19532f6e34100cc754492799b69d%26sysparm_cancelable%3Dtrue%26sysparm_editable%3Dtrue%26sysparm_active_panel%3DaddWidgetSideContent
https://developer.servicenow.com/connect.do#!/share/contents/6249193_scriptless_scheduled_jobs?v=1.01&t=RATINGS_REVIEWS&page=1
https://www.youtube.com/watch?v=lrs20pIn0Z8
https://youtu.be/lrs20pIn0Z8
........................................................................................................................
Interactive Filters (Reports and Dashboard)
........................................................................................................................
https://dev81532.service-now.com/nav_to.do?uri=%2Fsysauto_script.do%3Fsys_id%3D-1%26sys_is_list%3Dtrue%26sys_target%3Dsysauto_script%26sysparm_checked_items%3D%26sysparm_fixed_query%3D%26sysparm_group_sort%3D%26sysparm_list_css%3D%26sysparm_query%3D%26sysparm_referring_url%3Dsysauto_script_list.do%26sysparm_target%3D%26sysparm_view%3D
..................................
Scriptless Scheduled Jobs
..................................
https://youtu.be/lrs20pIn0Z8
https://developer.servicenow.com/connect.do#!/share/contents/6249193_scriptless_scheduled_jobs?v=1.01&t=PRODUCT_DETAILS
/****************************************************************************************************************************
* Debug ACLs
*****************************************************************************************************************************/
https://docs.servicenow.com/bundle/rome-platform-administration/page/administer/contextual-security/concept/c_AccessControlRulesDebug.html
/**************************************************************************
* Changes effective from today
***************************************************************************/
BR:
When on display
(function executeRule(current, previous /*null when async*/) {
var dt1 = new GlideDateTime(current.getValue('sys_created_on'));
var dt2 = new GlideDateTime("2021-09-15 00:00:00");
var diff = GlideDateTime.subtract(dt2, dt1);
var daysAgo = diff.getDayPart();
//gs.addInfoMessage(daysAgo);
if(daysAgo < 0 && daysAgo > -18885 )
g_scratchpad.created_on = "before";
else{
g_scratchpad.created_on = "after";
}
})(current, previous);
Client Script:
OnLoad
function onLoad() {
var created_on = g_scratchpad.created_on;
if(created_on == "before"){
//g_form.addInfoMessage("before");
g_form.setMandatory("field_name",false);
g_form.setDisplay("field_name",false);
}else if(g_form.getValue("type") != "standard"){
//g_form.addErrorMessage("after");
g_form.setMandatory("field_name",true);
g_form.setDisplay("field_name",true);
}
if ((g_form.getValue("type") == "standard")){
g_form.setMandatory("field_name",false);
g_form.setDisplay("field_name",false);
}
}
/*****************************************************************************************************************************************
* Portal User Impersonation
* and backend access
*****************************************************************************************************************************************/
STEP 1: Create Widget
Name : Impersonate User
ID : impersonate_user
......................................................................................................................................
Body HTML template
......................................................................................................................................
<div class="container-fluid" ng-init="getRecentImpersonation()">
<div class="row">
<div class="btn-group btn-group-sm btn-group-justified" role="group">
<label class="btn btn-info btn-sm" ng-model="c.selectedAction" uib-btn-radio="'sp'">Service Portal</label>
<label class="btn btn-primary btn-sm" ng-model="c.selectedAction" uib-btn-radio="'classic'">Classic UI</label>
</div>
</div>
<div class="row top-buffer" ng-if="data.isImpersonating">
<div class="btn-group btn-group-sm btn-group-justified" role="group">
<label ng-click="impersonate(c.data.realUser)" class="btn btn-danger btn-lg btn-block">
<i class="fa fa-stop m-r-sm"></i>
STOP Impersonating</label>
</div>
</div>
<div class="row top-buffer">
<div class="record-picker">
<sn-record-picker field="c.data.toImpersonate" table="'sys_user'" display-field="'name'" on-change="impersonate(c.data.toImpersonate.value)"
display-fields="'user_name'" search-fields="'name'" page-size="100" placeholder="Search for user" options="{cache: true, allowClear: false}"
default-query="'active=true^locked_out=false^web_service_access_only=false^ORweb_service_access_onlyISEMPTY'"
value-field="'sys_id'">
</sn-record-picker>
</div>
</div>
<div class="row top-buffer">
<div class="panel panel-default">
<div class="panel-heading">
<h5 class="panel-title">
${Recent Impersonations}
</h5>
</div>
<a ng-bind="rec.user_display_value" ng-repeat="rec in recentImpersonations" href="javascript:void(0)" class="list-group-item ng-binding ng-scope"
ng-click="impersonate(rec.user_sys_id)"></a>
</div>
</div>
</div>
......................................................................................................................................
CSS:
......................................................................................................................................
.top-buffer {
margin-top:20px;
}
......................................................................................................................................
Client controller
......................................................................................................................................
api.controller=function($scope, $http, $window) {
/* widget controller */
var c = this;
c.data.toImpersonate = {};
c.selectedAction = {};
$scope.impersonate = function(userName){
//If we don't have a user we can't impersonate
if(!userName){
return;
}
//Call to the impersonation api with username/sys_id
$http.post("/api/now/ui/impersonate/" + userName, {}).success(function(){
$scope.showError = false;
if(c.selectedAction === "classic"){
window.location = "/";
}else if(c.selectedAction === "sp" || c.selectedAction === null){
window.location.reload();
}else{
window.location.reload();
}
}).error(function(response){
if(response.error){
$scope.showError = true;
$scope.error = response.error;
console.warn("Impersonate Failed! with error:", response.error);
}
})
};
//call to the impersonation api Get recent impersonations
$scope.getRecentImpersonation = function(){
$http.get("/api/now/ui/impersonate/recent", {}).success(function(response){
$scope.showError = false;
$scope.recentImpersonations = response.result;
}).error(function(response){
if(response.error){
$scope.showError = true;
$scope.error = response.error;
console.warn("Get Recent Impersonations Failed! with error:" + response.error);
}
})
};
};
......................................................................................................................................
Server script
......................................................................................................................................
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
data.isImpersonating = new GlideImpersonate().isImpersonating();
data.realUser = gs.getImpersonatingUserName();
})();
STEP 2: Create Widget
Name : Impersonate User Entry
ID : impersonate-user-entry
......................................................................................................................................
Body HTML template
......................................................................................................................................
<div>
<!-- your widget template -->
</div>
......................................................................................................................................
CSS
......................................................................................................................................
Nothing
......................................................................................................................................
Client controller
......................................................................................................................................
api.controller=function() {
/* widget controller */
var c = this;
};
......................................................................................................................................
Server script
......................................................................................................................................
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
data.canImpersonate = new GlideImpersonate().canImpersonate(gs.getUserID());
data.isImpersonating = new GlideImpersonate().isImpersonating();
data.realUser = gs.getImpersonatingUserName();
if (data.canImpersonate || data.isImpersonating) {
data.show_menu_entry = true;
}
else {
data.show_menu_entry = false;
}
})();
......................................................................................................................................
Link
......................................................................................................................................
function link(scope, element, attrs, controller) {
var $uibModal = $injector.get('$uibModal');
// Add entry to navbar
if(scope.data.show_menu_entry && !$('#impersonation')[0]) {
$('#sp-nav-bar ul li.hidden-xs.dropdown ul.dropdown-menu li:first').after('<li style="cursor: pointer;"><a role="link" id="impersonation">${Impersonate User}</a></li>');
$('#sp-nav-bar ul li.visible-xs-block:first').after('<li class="visible-xs-block" style="cursor: pointer;"><a role="link" id="impersonation">${Impersonate User}</a></li>');
}
$("#impersonation").click(function() {
$uibModal.open({
templateUrl: 'impersonate-widget', //ng-template
scope: scope
})
});
}
......................................................................................................................................
Angular ng-template
......................................................................................................................................
ID : impersonate-widget
Template:
<div class="panel panel-default">
<h3 class="padder-md">
Impersonate User
</h3>
<div class="modal-header">
<widget id="impersonate_user"></widget>
</div>
</div>
STEP : 3 Add Header - Theme CSS variables
At the bottom of the Theme
......................................................................................................................................
Theme CSS variables - This add Icons to the drop down menu
......................................................................................................................................
#sp-nav-bar > ul:nth-child(2) > li.hidden-xs.dropdown.ng-scope.open > ul > li.ng-scope > a:before {
content: "\f08b"; /* Sign Out */
font-family: FontAwesome;
padding-right: 5px;
}
#sp-nav-bar > ul:nth-child(2) > li.hidden-xs.dropdown.ng-scope.open > ul > li:nth-child(1) > a:before {
content: "\f007"; /* Profile */
font-family: FontAwesome;
padding-right: 8px;
}
#impersonation:before {
content: "\f06e"; /* Impersonate User */
font-family: FontAwesome;
padding-right: 6px;
margin-left: -2px;
}
.m-n {
font-weight: bold;
color: $info;
}
STEP : 4 Go to the portal home page and add the widget created in STEP 2
Name: Impersonate User Entry
......................................................................................................................................
Drag and drop
......................................................................................................................................
After Typeahead Search
/*****************************************************************************************************************************************
* Portal to backend access
*
*****************************************************************************************************************************************/
STEP : goto: Portal -> Theme -> Header
sp_header_footer.list
......................................................................................................................................
Body HTML template
......................................................................................................................................
<ul class="dropdown-menu" role="menu" aria-label="{{::data.profileBtnMsg}}">
<li role="presentation"><a tabindex="-1" ng-href="?id=user_profile&sys_id={{::user.sys_id}}" role="menuitem">${Profile}</a></li>
<li ng-if="::data.advanced_view"><a target="_blank" ng-href="/nav_to.do" role="menuitem">${Advanced View}</a></li>
<li ng-if="::!(isViewNative || isViewNativeTablet)" role="presentation"><a tabindex="-1" href="{{::portal.logoutUrl}}" role="menuitem">${Logout Me}</a></li>
</ul>
......................................................................................................................................
Server Script
......................................................................................................................................
if(gs.getUser().hasRole("admin"))
//if(gs.getUser().hasRole(gs.getProperty("sn.advanced.view")))
data.advanced_view = true;
......................................................................................................................................
......................................................................................................................................
/*****************************************************************************************************************************************
* Portal access popup warning
*
*****************************************************************************************************************************************/
STEP : Create Widget
Name: Access PopUp Banner
ID: access_popup_banner
......................................................................................................................................
Body HTML template
......................................................................................................................................
<script type="text/ng-template" id="modalTemplate">
<div class="panel">
<div class="panel-body wrapper-xl">
<div style="font-weight: bold; color:#254B70;">
<center>
iDevOps LLC ServiceNow Labs
</center>
</div>
<br>
<div style="font-weight: bold; color:#800000;">
<center>
NOTICE TO ALL USERS
</center>
</div>
<br>
<div style="color:#202020;">
<div>
Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and
scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with
</div>
<br>
<div>
the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
<br>
<div>
the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
<br>
<div>
the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</div>
<ul>
<br>
<li>
the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</li>
<li>
At the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</li>
<li>
The the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</li>
<li>
You the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.
</li>
</ul>
</div>
</div>
<div class="panel-footer text-right">
<button class="btn btn-primary" ng-click="c.closeModal()">${Accept}</button>
<button class="btn btn-primary" ng-click="c.rejectWarning()">${Reject}</button>
</div>
</div>
</script>
......................................................................................................................................
CSS
......................................................................................................................................
Nothing
......................................................................................................................................
Client controller
......................................................................................................................................
api.controller=function($uibModal, $scope,$location) {
/* widget controller */
var c = this;
c.openModal = function() {
c.modalInstance = $uibModal.open({
templateUrl: 'modalTemplate',
scope: $scope,
backdrop: 'static'
});
}
c.closeModal = function() { //Accepted
c.data.status = true;
c.server.update();
c.modalInstance.close();
}
c.rejectWarning = function() {//Rejected
c.data.status = false;
c.server.update();
$location.url("/sp");
}
//alert(c.data.checkUp);
if(c.data.checkUp)
c.openModal();
};
......................................................................................................................................
Server script
......................................................................................................................................
(function() {
/* populate the 'data' object */
/* e.g., data.table = $sp.getValue('table'); */
var userId = gs.getUserID();
/*
if(input){
var grx = new GlideRecord('u_tracker_record');
grx.addQuery('u_user_targeted',userId)
grx.query();
if(grx.next()){
if(input.status){
grx.u_security_record_log += gs.now()+' '+gs.getUserDisplayName()+' '+options.accept_phrase+' \n';
grx.u_last_checked_in = gs.now();
}else{
grx.u_security_record_log += gs.now()+' '+gs.getUserDisplayName()+' '+options.reject_phrase+' \n';
}
grx.update();
}
}*/
/*
var checkSecurity = function(id){
var gr = new GlideRecord('u_tracker_record');
gr.addQuery('u_user_targeted',id)
gr.query();
if(gr.next()){
var lastUpdate = gr.u_last_checked_in;
var gd = new GlideDate();
var today = gd.getByFormat("yyyy-MM-dd");
if(today==lastUpdate){
return false;
}else{
return true;
}
}else{
var grCreate = new GlideRecord('u_tracker_record');
grCreate.initialize();
grCreate.u_user_targeted = id;
grCreate.u_security_record_log = options.start_log +' '+ gs.now()+'\n';
grCreate.insert();
return true;
}
}*/
data.checkUp = true;
//data.checkUp = checkSecurity(userId);
})();
......................................................................................................................................
Option schema
......................................................................................................................................
[{"name":"start_log","section":"other","default_value":"Security Check-in Form Created on","label":"Start Log","type":"string"},
{"hint":"Acknowledged the Notice","name":"accept_phrase","section":"other","default_value":"Acknowledged the Notice",
"label":"Accept Phrase","type":"string"},{"hint":"Rejected the Notice","name":"reject_phrase","section":"other",
"default_value":"Rejected the Notice","label":"Reject Phrase","type":"string"}]
STEP 2: Add the widget to the home page
//Incident onLoad : KeywordSearch
function onLoad() {
var env = typeof g_form.initialize === 'undefined' ? 'mobile' : 'desktop';
if (env == 'desktop')
return;
var bs = "";//business_service
var sf = "";//service_offering
var short_desc = g_form.getValue("short_description");
short_desc = short_desc.substring(0,80);
g_form.getReference("business_service",function(s){
bs = s.name || "";
bs = bs.substring(0,35);
g_form.getReference("service_offering",function(o){
var sf = o.name || "";
sf = sf.substring(0,35);
var new_short_desc = "";
if(short_desc.indexOf(bs) == -1){
new_short_desc = short_desc+" "+bs;
}else{
new_short_desc = short_desc;
}
if(short_desc.indexOf(sf) == -1){
new_short_desc = short_desc+" -- "+bs+" "+sf;
}else{
new_short_desc = short_desc;
}
if(new_short_desc != ""){
g_form.setValue("short_description", new_short_desc);
var desc = g_form.getValue("description");
}
});
});
}
//Incident : OnChange In Agent VIPorSVIP
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
//If the page isn't loading
if (!isLoading) {
//If the new value isn't blank
if(newValue != '') {
var env = typeof g_form.initialize === 'undefined' ? 'mobile' : 'desktop';
if (env == 'desktop')
return;
g_form.clearMessages();
g_form.getReference("u_affected_user", function(objUser){
if(objUser.vip == "true" || objUser.vip == true ){
g_form.showFieldMsg('u_affected_user','VIP','error',true);
}else if(objUser.u_sensitive_vip == "true" || objUser.u_sensitive_vip == true ){
g_form.showFieldMsg('u_affected_user','Sensitive VIP','error',true);
}
});
}
}
}
//Incident : onLoad AgentVIPorSensitiveVIP
function onLoad() {
var env = typeof g_form.initialize === 'undefined' ? 'mobile' : 'desktop';
if (env == 'desktop')
return;
g_form.clearMessages();
if(g_form.getValue("u_affected_user"))
g_form.getReference("u_affected_user", function(objUser){
if(objUser.vip == "true" || objUser.vip == true ){
//g_form.showFieldMsg('u_affected_user','VIP','info',true);
g_form.showFieldMsg('u_affected_user','VIP','error',true);
}else if(objUser.u_sensitive_vip == "true" || objUser.u_sensitive_vip == true ){
//g_form.showFieldMsg('u_affected_user','Sensitive VIP','info',true);
g_form.showFieldMsg('u_affected_user','Sensitive VIP','error',true);
}
});
if(g_form.getValue("caller_id"))
g_form.getReference("caller_id", function(objUser){
if(objUser.vip == "true" || objUser.vip == true ){
//g_form.showFieldMsg('caller_id','VIP','info',true);
g_form.showFieldMsg('caller_id','VIP','error',true);
}else if(objUser.u_sensitive_vip == "true" || objUser.u_sensitive_vip == true ){
//g_form.showFieldMsg('caller_id','Sensitive VIP','info',true);
g_form.showFieldMsg('caller_id','Sensitive VIP','error',true);
}
});
}
//Incident : onChange In Agent VIPorSVIP for Caller
function onChange(control, oldValue, newValue, isLoading, isTemplate) {
//If the page isn't loading
if (!isLoading) {
//If the new value isn't blank
if(newValue != '') {
var env = typeof g_form.initialize === 'undefined' ? 'mobile' : 'desktop';
if (env == 'desktop')
return;
g_form.clearMessages();
g_form.getReference("caller_id", function(objUser){
if(objUser.vip == "true" || objUser.vip == true ){
//g_form.showFieldMsg('caller_id','VIP','info',true);
g_form.showFieldMsg('caller_id','VIP','error',true);
}else if(objUser.u_sensitive_vip == "true" || objUser.u_sensitive_vip == true ){
//g_form.showFieldMsg('caller_id','Sensitive VIP','info',true);
g_form.showFieldMsg('caller_id','Sensitive VIP','error',true);
}
});
}
}
}
//FOR GLOBAL APPLICATIONS
https://developer.servicenow.com/dev.do#!/reference/api/rome/server_legacy/c_TableUtilsAPI
var table = new TableUtils("cmdb_ci_server");
gs.print(table.getAbsoluteBase());
var table = new TableUtils("task");
gs.print(table.getAllExtensions());
var table = new TableUtils("cmdb_ci_server");
gs.print(table.getHierarchy());
// Get the tables that extend the table
var table = new TableUtils("cmdb_ci_computer");
var tableArrayList = table.getTableExtensions();
// Use the j2js method to convert the Java ArrayList to JavaScript
gs.include("j2js");
var tableArray = j2js(tableArrayList);
// Write the value of each element in the JavaScript array
var i = 0;
while ( i < tableArray.length ) {
gs.print("Table with index " + i + ": " + tableArray[i]);
i++;
}
// Get the hierarchy of tables
var table = new TableUtils("cmdb_ci_computer");
var tableArrayList = table.getTables();
// Use the j2js method to convert the Java ArrayList to JavaScript
gs.include("j2js");
var tableArray = j2js(tableArrayList);
// Write the value of each element in the JavaScript array
var i = 0;
while ( i < tableArray.length ) {
gs.print("Table with index " + i + ": " + tableArray[i]);
i++;
}
//FOR SCOPE APPLICATIONS
https://developer.servicenow.com/dev.do#!/reference/api/orlando/server/no-namespace/c_GlideTableHierarchyScopedAPI
//-------------------------------------------------------------
// TableHierarchy
//--------------------------------------------------------------
var table = new GlideTableHierarchy("incident");
gs.info(table.getTables());
Output:
incident,task
//-----------------------------------------------------------
//
//----------------------------------------------------------
var table = new GlideTableHierarchy("task");
gs.info(table.getTableExtensions());
//-------------------------------------------------------------
//
//------------------------------------------------------------
var table = new GlideTableHierarchy("task");
gs.info(table.getAllExtensions());
//-------------------------------------------------------------
//
//-------------------------------------------------------------
var table = new GlideTableHierarchy("incident");
gs.info(table.getHierarchy());
//----------------------------------------------------------------
//
//--------------------------------------------------------------
var table = new GlideTableHierarchy("cmdb_ci_server");
gs.info(table.getRoot());
//--------------------------------------------------------------
//
//--------------------------------------------------------------
var table = new GlideTableHierarchy("sys_user");
gs.info(table.isSoloClass());
//----------------------------------------------------------------
//
//----------------------------------------------------------------
var table = new GlideTableHierarchy("incident");
gs.info(table.hasExtensions());