Posts

Showing posts from May, 2022

ServiceNow ARRAYS: looking for matching values in alerts and events (e.g. problemID)

 (ServiceNow ) gs . info ( "checking list of today's Alerts by common problemID" ); var grAlerts = new GlideRecord ( 'em_alert' ); grAlerts . addQuery ( 'source' , 'SGO-Dynatrace' ); grAlerts . addEncodedQuery ( 'sys_created_onONToday@javascript:gs.beginningOfToday()@javascript:gs.endOfToday()' ); grAlerts . query (); grAlerts . orderBy ( 'message_key' ); gs . info ( 'TOTAL SGO ALERTS FOR TODAY: ' + grAlerts . getRowCount ()); var dupl_prbID_arr = []; var dupl_cmdbci_arr = []; while ( grAlerts . next ()){ var sAddInfo = JSON . parse ( grAlerts . additional_info ); var sProblemID = sAddInfo . ProblemID + "" ; //gs.info('message key=' + grAlerts.message_key + '; ProblemID=' + sProblemID); dupl_cmdbci_arr . push ( grAlerts . cmdb_ci + "" ); dupl_prbID_arr . push ( sProblemID ); } dupl_prbID_arr . sort (); dupl_cmdbci_arr . sort (); c

ServiceNow: retrieve a JSON Array element by its KEY value

 in this example, we wish to retrieve the blue highlighted key value from the JSON array tagsOfAffectedEntities : {   "ProblemDetailsJSON" : {     "id" : "xxxx",     "startTime" : 1652690280000,     "endTime" : 1652690280000,     "displayName" : "yyyy",     "impactLevel" : "INFRASTRUCTURE",     "status" : "CLOSED",     "severityLevel" : "RESOURCE_CONTENTION",     "commentCount" : 3,     " tagsOfAffectedEntities " : [ {       "context" : "CONTEXTLESS",       "key" : "Application"     }, {       "context" : "CONTEXTLESS",       " key " : "SZCOFF",       " value " : " SZCOFF12345 "     }, {       "context" : "CONTEXTLESS",       "key" : "K8s container xxx",       "value" : "xxxx"    

ServiceNow Regex: retrieve a url section

 var sStr=" https: // xxxx.live.dynatrace.com / #problems/problemdetails;pid=-400331722456210xxxx_16526899800xxxx"; var iMatch1=sStr.indexOf("/", sStr.indexOf("/")+1); var iMatch2=sStr.indexOf("/", sStr.indexOf("/")+2); //gs.print(iMatch2); gs.print(sStr.substring(iMatch1+1, iMatch2));  ---  output: *** Script: 35 *** Script: xxxx.live.dynatrace.com  

ServiceNow REGEX: get a string between 2 characters

  in this example, grab a string between first and second **   var stext = "## OPEN Problem P-xxxxx in environment * Non Production *\n\nProblem detected at: 10:42 (UTC) 26.05.2022\n\n---\n**1 impacted infrastructure component**" ; //--OPTION 1: var sArr = stext . split ( "*" ); gs . print ( 'option1 result' + sArr [ 1 ]); //OPTION 2: var first = stext . indexOf ( "*" ); gs . print ( first ); var second = stext . indexOf ( "*" , first + 1 ); gs . print ( second ); var mySubString = stext . substring ( first + 1 , second ); gs . print ( 'option2 result:' + mySubString );     (ServiceNow )

ServiceNow - Slack integration

 https://api.slack.com/tutorials/slack-apps-and-postman   https://docs.servicenow.com/bundle/sandiego-it-service-management/page/product/itsm-tcm/concept/im-slack-collaboration.html    https://docs.servicenow.com/bundle/sandiego-application-development/page/administer/integrationhub/concept/slack-spoke.html

ServiceNow - How to cancel a fix script execution

 set the progress worker entry to cancelled go to 'active transactions' > locate the backgroundProgressJob process> right-click and kill

ServiceNow - Script to tidy up large chunks of sterile cmdb data

var instURL = gs . getProperty ( 'glide.servlet.uri' ); if ( instURL . indexOf ( 'https://xxxx_prod.service-now.com' ) > - 1 ) { gs . print ( 'do not run on prod' ); } else { var cmdb_rel_count = getCMDBciRELcount (); var cmdb_endpoint_count = getCMDBendpointCount (); var runDelete = false ; //--counts only if false, no delete runDelete = true ; //--deletes/tidyup enabled gs . log ( 'Script start...[cmdb_ci_rel count=' + cmdb_rel_count + ']' , 'CMDB Tidyup' ); gs . log ( 'Script start...[cmdb_ci_endpoint_manual count=' + cmdb_endpoint_count + ']' , 'CMDB Tidyup' ); gs . log ( 'Script start...[runDelete=' + runDelete + ']' , 'CMDB Tidyup' ); cmdb_tidyup ( runDelete ); cmdb_rel_count = getCMDBciRELcount (); cmdb_endpoint_count = getCMDBendpointCount (); gs . log ( 'Script

ServiceNow - Workflow showing last updated by a non admin user

  Workflows seem to be updated by the first person that use them once they are published   this might be something ServiceNow address as some point but still appears to be the case on San Diego version 😆

ServiceNow - Target a segment of records in GlideRecord using chooseWindow

 https://developer.servicenow.com/dev.do#!/reference/api/sandiego/server/c_GlideRecordScopedAPI  Example This show returning records 3 and 4 from the Incident table. var now_GR = new GlideRecord( 'incident' ); now_GR.orderBy( 'number' ); now_GR.chooseWindow( 2 , 4 ); now_GR.query(); while (now_GR.next()) { gs.info(now_GR.getValue( 'number' ) + ' is within window' ); }

ServiceNow - Create a custom sys properties page

Image
 https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0715835   Browse to the following location on the instance: System Properties -> Categories. A list of System Property Categories should appear.  Click the New button to create a new Category. Fill out the following fields on the new System Property Category record: Name : This is the name for the category as it will displayed in the list and in associated lists for properties.  It should be the exact same as a CategoryName specified in the URL in the Arguments field of the module created in the steps above. Title : This will be text that will be displayed above this grouping of properties on the page.  This is an HTML editor field so can include HTML formatted text and can be as lengthy as needed, to include details regarding the properties in this section.   Once satisfied with the Category record, click the Submit button to save this category to the system. Repeat for each category that is t

ServiceNow - Approval view of demand form: using a formatter

  Approval Summarizer formatter (Displaying and amending view of item to be approved within the approval record)   Introduction: When opening and viewing an approval record/form, you will typically not see the actual task or record that you are about to approve or reject. Instead, you would always see a reference field pointing to the item that needs to be approved, whether it is a change request, request item, demand, Aetc. There is however, a feature provided Out-Of-The-Box by ServiceNow, which allows a summary to be displayed of the item to be approved within the same approval record. This, however, requires a small customisation to utilise. Since (at least) the Paris release, this feature had become available on the approval form without requiring any customisations.   Displaying item to be approved (on the backend approval form): If the 'Approval Summarizer' section is not already available on the approval form, then you can add it by performing the f