ARRAYUTILS SERVICENOW | All The Use Cases with Implementation

ArrayUtil is a custom script include in ServiceNow that provides a variety of useful functions for working with arrays. An array is a data structure that stores a collection of elements, such as numbers or strings, in a single variable. Arrays are commonly used in programming to store and manipulate large sets of data. The functions provided by ArrayUtil make it easier to perform common array operations in ServiceNow.

WHAT IS ARRAYUTIL API IN SERVICENOW ?

ServiceNow ArrayUtil API is a script include which contains useful functions through which we can directly perform some JavaScript Array logics instead of writing multiline code.
ArrayUtil methods are available to any server side script. Methods Like:  concat(), unique(), union(), intersect(), ensureArray(), contains(), indexOf() etc.

USE CASE SCENARIO'S AND SOLUTION OF ARRAYUTILS:

Belwo are the use case scenarios to explore each and every method of ArrayUtil in ServiceNow:
1. MERGE TWO ARRAYS.
2. CHECK IF ARRAY CONTAINS THE REQUIRED VALUE. 
3. FIND WHAT ALL DISTINCT VALUE GIVEN ARRAY CONTAINS IN COMPARISION TO OTHER AVAILABLE ARRAYS.
4. FIND OUT THE INDEX OR POSITION OF REQUIRED ELEMENT IN AN ARRAY.
5. FIND WHAT ALL ELEMENTS ARE COMMON IN ALL GIVEN ARRAYS
5. COMBINE ALL ARRAYS BUT, IT SHOULD ONLY CONTAIN UNIQUE VALUES.
6. FIND WHAT ALL UNIQUE VALUE A SINGLE ARRAY CONTAINS.
7. CONVERT JAVASCRIPT OBJECT TO JAVASCRIPT ARRAY.

Below is the Code exploring each and every method of ArrayUtil:


// Array Utils

var firstArray= ['Green','Brown','Red','Orange','Yellow','Orange'];
var secondArray=['Purple','Black','Green','Blue','Orange'];
var thirdArray=['White','Orange','Green','pink'];
var demoObject={name:'Bean Plant',color:'Green',vegetable:'Beans'};
var arrayUtil=new ArrayUtil();

// Merge two arrays
    gs.info(arrayUtil.concat(firstArray,secondArray));

// Check array contains the required value or not
    gs.info(arrayUtil.contains(firstArray,'Yellow'));

// Find out all the different values required array contain in comparision with other
    gs.info(arrayUtil.diff(firstArray,secondArray,thirdArray));

// Find out the index or position of an element in an array
    gs.info(arrayUtil.indexOf(firstArray,'Orange',2));

// find out only common values in all the array available.
    gs.info(arrayUtil.intersect(firstArray,secondArray,thirdArray));

// find out all the unique elements or values available in all the available array
    var fourthArray=arrayUtil.union(firstArray,secondArray,thirdArray);
    gs.info(fourthArray);

// Find out the unique value available in an single array or required array
    gs.info(arrayUtil.unique(firstArray));

// Convert Javascript object to javascript array
    gs.info(Array.isArray(demoObject));
    gs.info(arrayUtil.ensureArray(demoObject));
    gs.info(JSON.stringify(arrayUtil.ensureArray(demoObject)));
 


what is arrayutils in servicenow,arrayutil script include,array-utils,servicenow api array utils, example of arrayutils


ArrayUtil is a custom script include in ServiceNow that provides a variety of useful functions for working with arrays. An array is a data structure that stores a collection of elements, such as numbers or strings, in a single variable. Arrays are commonly used in programming to store and manipulate large sets of data. The functions provided by ArrayUtil make it easier to perform common array operations in ServiceNow.

Overall, ArrayUtil is a powerful tool for working with arrays in ServiceNow. Its functions make it easier to perform common array operations, such as searching, sorting, and grouping. If you're working with arrays in ServiceNow, be sure to check out ArrayUtil and see how it can help streamline your workflows and improve your efficiency.

1 comment:

Thankyou !!!!

Powered by Blogger.