Skip to main content

Posts

Showing posts with the label regex

ServiceNow Javascript substr deprecated

 ServiceNow Javascript substr deprecated (Vancouver version) var password='hodljdsnw340949'; var len=9; I would be inclined to replace this:     return password. substr (0, len); with:     return password. substring (0, len); or alternatively use a regex ( var sRegexQ='/^.{'+ len +'}/' var pattern= new SNC.Regex(sRegexQ); var result = pattern.match(password); return(result); )

ServiceNow Generate a Password Function

ServiceNow Generate a Password Function e.g. use for AD pwd var spassword = generatePassword ( 10 ); gs . print ( spassword ); function generatePassword ( len ) { var length = ( len ) ? ( len ) : ( 10 ); var string = "abcdefghijklmnopqrstuvwxyz" ; //to upper var numeric = '0123456789' ; var punctuation = '!@#$%^&*' ; var password = "" ; var character = "" ; var crunch = true ; while ( password . length < length ) { entity1 = Math . ceil ( string . length * Math . random () * Math . random ()); entity2 = Math . ceil ( numeric . length * Math . random () * Math . random ()); entity3 = Math . ceil ( punctuation . length * Math . random () * Math . random ()); hold = string . charAt ( entity1 ); hold = ( password . length % 2 == 0 ) ? ( hold . toUpperCase ()) : ( ho...

ServiceNow inbound email action to read values from a table

 courtesy of Jithender Nayini example table contained in inbound email:         inbound action code: // Note: current.opened_by is already set to the first UserID that matches the From: email address current . caller_id = gs . getUserID (); current . comments = "received from: " + email . origemail + "\n\n" + email . body_text ; current . short_description = email . subject ; //current.category = "request"; current . incident_state = IncidentState . NEW ; current . notify = 2 ; current . contact_type = "email" ; var htmlcode = email . body_html ; htmlcode = htmlcode . replace ( /<style([\s\S]*?)<\/style>/gi , '' ); htmlcode = htmlcode . replace ( /<script([\s\S]*?)<\/script>/gi , '' ); htmlcode = htmlcode . replace ( /<\/div>/ig , '\n' ); htmlcode = htmlcode . replace ( /<\/li>/ig , '\n' ); htmlcode = htmlcode . replace ( /<li...

ServiceNow server side regex (SNC.regex) - extract text between html tags

ServiceNow server side regex (SNC.regex) - extract text between html tags  var sStr='<h3>OPEN Problem P-22061362 in environment <i>Non Production</i></h3><br><small>Problem detected at: 10:27 (UTC) 09.06.2022</small><hr><b>1 impacted infrastructure component</b><hr><br><div><span>Process</span><br>';   var sRegexQ='/(?<=\<small\>)(\s*.*\s*)(?=\<\/small\>)/' var pattern= new SNC.Regex(sRegexQ);   var results = pattern.match(sStr);        while (results !== null) {                gs.print("match: " + results[0]);                results = pattern.match();        }

ServiceNow server side regex reference

ServiceNow server side regex reference  https://docs.servicenow.com/en-US/bundle/sandiego-application-development/page/script/general-scripting/concept/c_RegularExpressionsInScripts.html    e.g. var sRegexQ='/<small>(.*?)</small>/'; var pattern= new SNC.Regex(sRegexQ);  var sStr='<h3>OPEN Problem P-22061362 in environment <i>Non Production</i></h3><br><small>Problem detected at: 10:27 (UTC) 09.06.2022</small><hr><b>1 impacted infrastructure component</b><hr><br><div><span>Process</span><br>'; var results = pattern.match(sStr);        while (results !== null) {                gs.print("match: " + results[0]);                results = pattern.match();        } *** Sc...

ServiceNow Regex: retrieve a url section

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

 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 REGEX grab the following string: between 2 words

ServiceNow REGEX grab the following string: between 2 words to get the value highlighted in yellow:  [code]<h3>OPEN Problem P-2107xxx in environment <i>Non Production</i></h3><br /><small> Problem detected at: 02:39 (UTC) 28.07.2021 </small><hr /><b>1 impacted application</b>< regex: var sDetails = grPrb . details + "" ; var testRE = sDetails . match ( " at: (.*) </small " ); gs . print ( testRE [ 1 ]); *** Script: 02:39 (UTC) 28.07.2021

ServiceNow Running your own health scan, for improved reporting of culprit objects

ServiceNow Running your own health scan, for improved reporting of culprit objects  (c) Shahed Shah --- /** * Name: Config Review Script * Created: 2019-07-19 * Author: Shahed Ali Shah @ Cloudefy Ltd * Usage: Inside the *process* function, uncomment the function for the intended review * Do not run all the functions. */ var reviewScript = { WHITELIST : [ 'sys_script_fix' , 'clone_cleanup_script' ], // of tables when running performMatch or findMatch process : function () { // WARNING - Try to reduce how many heavy scripts you run at once //this.hardCodedSysIDs(); // HEAVY: Hard-coded Sys IDs in Server-Side Scripts // this.ohardCodedSysIDs([ // { // table: 'sys_script', // field: 'script', // query: 'active=true' // }, // { // table: 'sys_script_include', // fi...