logo

NJP

ServiceNow- useful admin focused widget and portal page for Dynatrace ITOM - serves as a test harness

Import · Jun 14, 2022 · article

(does not include the script include code)

HTML:

DYNATRACE DOCUMENTATION

DYNATRACE ENVIRONMENTS

STAGING:
yyyyy.live.dynatrace.com

PROD:
ppppp.live.dynatrace.com

Script include calls

Extract Alert info

Enter Alert number here

Click to extract tags from the JSON

Alert tags:

key tags extracted from em\_alert.additional\_info field, not the full list necessarily

{{c.dynatraceADDLINFO}}

Callback Function Test

Select Dynatrace environment STAGING (yyyyyy) PROD (pppppp)
Enter entity name here

Click to check problem details/root cause SVCOFF

Problem Details (Rootcause) SVCOFF:

{{c.dynatraceSVCOFF}}

SVCOFF (Service Offering) name:

{{c.SVCOFF\_name}}

Full problem details (rootcauseinfo) payload:

{{c.dynatraceResponse}}

Get Random Allocation SVCOFF (from full problem details payload):

Click to randomly allocate svcoff

Random allocated SVCOFF:

{{c.dynatraceRandomSVCOFF}}

EXAMPLE EVENT PAYLOADS

Open Alert

{{::data.example\_payload\_open}}

Closed Alert

{{::data.example\_payload\_closed}}

client script

api.controller=function($scope) { /* widget controller */ var c = this; c.dynatraceResponse=''; c.dynatraceADDLINFO=''; c.dynatraceRandomSVCOFF=''; c.SVCOFF_name=''; $scope.runtheoperation = function() { //console.log("message", 'run the op'); c.server.get({ action: "get_rootcause", msg : "Running REST API GET operation to retrieve rootcause SVCOFF from Dynatrace...", sn_env : angular.element($('#dynatrace_environment')).val(), entity : angular.element($('#dynatrace_entity_name')).val() }).then(function(r){ var responseData=r.data.rootcauseinfo; var responseSVCOFF=r.data.rootcausesvcoff; var SVCOFF_name=r.data.svcoff_name; //alert('responseData='+responseData); //c.dynatraceResponse=responseData.join('\n'); c.dynatraceResponse=responseData; c.dynatraceSVCOFF=responseSVCOFF; c.SVCOFF_name=SVCOFF_name; }); }; $scope.runtheoperation_alert = function() { //console.log("message", 'run the op'); c.server.get({ action: "get_additionalinfo", msg : "extracting additional_info from alert...", alert_num : angular.element($('#alert_num')).val() }).then(function(r){ var responseAddInfoData=r.data.alertinfo; //alert('responseData='+responseData); //c.dynatraceResponse=responseData.join('\n'); c.dynatraceADDLINFO=responseAddInfoData; }); }; $scope.runtheoperation_random = function() { alert(angular.element($('#dynatrace_environment')).val() + '; alert='+angular.element($('#alert_num')).val()+ ' (in "Enter Alert number here" box)'); //console.log("message", 'run the op'); c.server.get({ action: "get_randomsvcoff", msg : "allocating random SVCOFF from problem details response payload...", sn_env : angular.element($('#dynatrace_environment')).val(), alert_num : angular.element($('#alert_num')).val() }).then(function(r){ //alert('Extracting from: ' + angular.element($('#results_full')).val()); var responseRandomSVCOFF=r.data.randomsvcoff; c.dynatraceRandomSVCOFF=responseRandomSVCOFF; }); };

}

server script

(function() { /* populate the 'data' object */ /* e.g., data.table = $sp.getValue('table'); */ var si=new sgo_itomevents_libraries(); data.example_payload_open = si.ExamplePayloadEvents_open(); data.example_payload_closed = si.ExamplePayloadEvents_resolved(); //data.rootcausesvcoff=''; if (input ){ if (input.action === "get_rootcause"){ var si=new sgo_itomevents_libraries(); data.rootcausesvcoff=(rootcause_info(input.sn_env, input.entity, si)); var sNum=data.rootcausesvcoff+""; data.svcoff_name=getSVCOFFname(sNum); data.rootcauseinfo=(rootcause_fullpayload(si)); } if (input.action === "get_additionalinfo"){ data.alertinfo=(rootcause_addl_info(input.alert_num)); } if (input.action === "get_randomsvcoff"){ data.randomsvcoff=(random_svcoff(input.alert_num, input.sn_env)); } }function random_svcoff(alert_number, env){ var resp=''; var sEnv='yyyyy'; if (env=='production'){ sEnv='ppppp'; } var grAlert=new GlideRecord('em_alert'); if (grAlert.get('number', alert_number)){ var si=new sgo_itomevents_libraries(); resp=si.getRandomSVCOFFfromTags(grAlert,sEnv); } return resp;}function rootcause_fullpayload(si){ //gs.addInfoMessage('entityname='+entityname); //gs.addInfoMessage('environment='+environment); var resp=si.getRootCauseInfo_rawPayload(); //gs.addInfoMessage('resp='+resp); return resp;} function rootcause_info(environment,entityname, si){ //gs.addInfoMessage('entityname='+entityname); //gs.addInfoMessage('environment='+environment); var resp2=si.getRootCauseInfo(entityname,environment); //gs.addInfoMessage('resp='+resp2); return resp2;}function rootcause_addl_info(alert_number){ var si=new sgo_itomevents_libraries(); var resp=si.extractAlertAdditionalInfoTags(alert_number); //gs.addInfoMessage('resp='+resp); return resp;} function getSVCOFFname(svcoffNum){ var sReturn=''; var grSO=new GlideRecord('service_offering'); grSO.addQuery('number', svcoffNum); grSO.query(); if (grSO.next()){ sReturn=grSO.getValue("name"); } return sReturn; }

})();

CSS

div.ghost{ background: ghostwhite; font-size: 15px; padding: 10px; border: 1px solid lightgray; margin: 10px;}

Haven't tested these all recently within global/local scopes, so feel free to have a play! option 1 use an encoded query embedded in the GlideRecord , e.g. var grProf = new GlideRecord ( 'x_cls_clear_skye_i_profile' ); grProf . addQuery ( 'status=1^ owner=NULL ' ); grProf . query (); even better use the glideRecord addNotNullQuery or addNullQuery option 2 JSUtil.nil / notNil (this might be the most powerful. See this link ) example: if ( current . operation () == 'insert' && JSUtil . notNil ( current . parent ) && ! current . work_effort . nil ()) option 3 there might be times when you need to get inside the GlideRecord and perform the check there, for example if the code goes down 2 optional routes depending on null / not null can use gs.nil : var grAppr = new GlideRecord ( 'sysapproval_approver' ); var grUser = new GlideRecord ( 'sys_user' ); if ( grUser . get ( 'sys_id' , current . approver )){

Classic UI : var sURL_editparam = gs . action . getGlideURI (). getMap (). get ( ' sysparm_aparameter ' ); if ( sURL_editparam == 'true' ) { gs . addInfoMessage ( 'parameter passed ); } Portal : var sURL_editparam = $sp . getParameter ( " sysparm_aparameter " ); if ( sURL_editparam == 'true' ) { gs . addInfoMessage ( 'parameter passed ); }

Call a script include to apply a reference qualifier on a catalog item variable: - variable reference qualifier dependent on another variable selection, in this case a variable referencing sys_user (requested_for) On the catalog item form. variable name to apply ref qual filter : retail_equipment variable reference qualifier (on cmdb table ): javascript : new refqual_functions (). lostStolen_getAssignedCIs (); client-callable script include ( refqual_functions) function : lostStolen_getAssignedCIs : function (){ //--called from variable set client script, for lost/stolen request (service catalog) gs . log ( current . variables . requested_for , 'retail_lostStolen_getAssignedCIs' ); return ( 'install_statusNOT IN8,7owned_by=' + current . variables . requested_for ); //owned_by=1269b79937f1060041c5616043990e41install_statusNOT IN8,7 },

View original source

http://www.cloudminus89.com/2022/06/servicenow-useful-admin-focused-widget.html