Posts

Showing posts from 2019

Delete v/s Splice for JavaScript Array

Use "splice" instead of "delete" to delete an item from an array because "Delete" replaces the item with undefined instead of the removing it from the array. var fruits = ["apple", "banana", "grapes"]; fruits.length; // return 3 delete fruits[1]; // return true fruits.length; // return 3 Instead var fruits = ["apple", "banana", "grapes"]; fruits.length; // return 3 fruits.splice(2,1) ; fruits.length; // return 2

Beautify JSON String

var myObj = {hello: "World"}; JSON.stringify(myObj, null, 4); // '{ // "hello": "world" // }'

String and Number Conversion in JavaScript

var myString = "999"; // Convert String to a number var myNumber = +myString; // → 999 // OR var myNumber = Number(myString) // → 999 // Convert String to negative number var myNegativeNumber = -myString; // → -999 // OR var myNegativeNumber = -Number(myString) // → -999

Show hidden variables on Service Portal using browser console

Since Service Portal uses Bootstrap, You can use those bootstrap specific classes to perform the required action $('.form-group.ng-hide').removeClass('ng-hide');

Generate random numbers in JS

function generateRandom(length) { var result = ''; var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; var charactersLength = characters.length; for ( var i = 0; i < length; i++ ) { result += characters.charAt(Math.floor(Math.random() * charactersLength)); } return result; }

Clear ServiceNow cache using scirpt

gs.cacheFlush();

Jumbled up JavaScript

Image

ServiceNow - Widget Editor shortcuts (MAC)

Image

Copy JS path from browser devtools

Image
With DevTools (Chrome 72) you can copy JS path from your browser

What is the use of document ID field in ServiceNow

Image
There are multiple ways to implement one-to-many relationship in ServiceNow Reference Fields GlideList Document ID fields ServiceNow has provided "Document ID" field to hold a reference of any table because at some times we have a requirement to hold the reference irrespective of the table. Document ID lets the user choose the table and the associated record