ai.util
Functions
Method | Parameters | Returns | Description |
|---|---|---|---|
apply( obj, config ) |
| Object | Copies all the properties of config to obj and returns obj. |
decodeBase64( encodedBase64 )
available in 2018.3 |
A string encoded as Base64. E.g. dGV4dA== | String | Returns a decoded Base64 string.
Text |
decodeHtml( encodedHtml )
available in 2018.3 |
A string with reserved characters translated in order to be used in HTML literals. Hello <b> [there] >words<! | String | Returns a string as raw HTML.
'Hello <b> [there] >words<!' |
decodeUrl( encodedUrl )
available in 2018.3 |
A string with an HTML encoded URL. E.g. https%3a%2f%2fwww.example.com%2ffings%2f%3fid%3d123%26more%3dwords%23hash | String | Returns a string with a raw URL.
https://www.example.com/fings/?id=123&more=words#hash |
decrypt( encryptedText ) |
| String | Returns the original, decrypted plain text string.
The ai.util.decrypt() function reverses the encryption process, taking an encrypted string (typically a stored password or API key) and converting it back to its original plain text format so it can be used within the CCDS script to authenticate against an external system or API. To set up this method, first set up your Pretty Good Privacy (PGP) encryption. See Set up PGP Encryption. |
encodeBase64( rawBase64 )
available in 2018.3 |
A string with text. E.g. Text | String | Encodes text as Base64.
dGV4dA== |
encodeHtml( rawHtml )
available in 2018.3 |
A string with raw HTML. E.g. 'Hello <b> [there] >words<!' | String | Returns a string with reserved characters translated in order to be used in HTML literals.
Hello <b> [there] >words<! |
encodeUrl( rawUrl )
available in 2018.3 |
A string with a raw URL. E.g. https://www.example.com/fings/?id=123&more=words#hash | String | Returns a raw URL as an encoded HTML.
https%3a%2f%2fwww.example.com%2ffings%2f%3fid%3d123%26more%3dwords%23hash |
encrypt( textToEncrypt ) |
| String | Returns the encrypted representation of the input string. This output should be used to store or pass sensitive credentials instead of the plain text.
The ai.util.encrypt() function applies an encryption algorithm (managed by the Workday Adaptive Planning platform) to the provided plain text string. This is primarily used in Custom Cloud Data Source (CCDS) scripts to protect credentials before storing them as configuration parameters in the integration setup. To set up this method, first set up your Pretty Good Privacy (PGP) encryption. See Set up PGP Encryption. |
format ( formatString, arg1, arg2....argN ) |
| String | Used to define a tokenized string and pass an arbitrary number of arguments to replace the tokens. Each token must be unique, and must increment in the format {0}, {1}, etc. |
isDate( value ) |
| Boolean | Returns true if the passed value is a JavaScript Date object. |
isUndefined( value ) |
| Boolean | Returns true if the passed value is 'undefined'. |
isDefined( value ) |
| Boolean | Returns true if the passed value is not 'undefined'. |
isArray( value ) |
| Boolean | Returns true if the passed value is a JavaScript array, otherwise false. |
isString( value ) |
| Boolean | Returns true if the passed value is a string. |
isNumber( value ) |
| Boolean | Returns true if the passed value is a number and is finite. |
isBoolean( value ) |
| Boolean | Returns true if the passed value is true or false. |
toArray( a, i, j ) | Array | ||
isPrimitive( value ) |
| Boolean | Returns true if the passed value is a String, Number or Boolean. |
sleep(timeInMilliseconds ) |
| Void | Suspends the current script for the specified time without consuming CPU. Use this instead of manual while-loop delays (for example, custom sleepX functions). |
Examples
//Example for ai.util.apply var sourceObj = {department:"Engineering"}; var destObj={}; ai.util.apply(destObj,sourceObj); ai.log.logInfo("Source Properties applied to Destination object: "+JSON.stringify(destObj)); // Source Properties applied to destination object: {department:Engineering} //Example for ai.util.decodeHtml var encodedHtml = "Hello <b> [there] >words<!"; var decodedvalue=ai.util.decodeHtml(encodedHtml); ai.log.logInfo("Decoded HTML is " +decodedvalue); // Decoded HTML is Hello [there] >words //Example for ai.util.encodeHtml var rawHtml = "Hello <b> [there] >words<!"; var encodedvalue=ai.util.encodeHtml(rawHtml); ai.log.logInfo("Encoded HTML is " +encodedvalue); // Encoded HTML is Hello <b> [there] >words<! //Example for ai.util.decodeBase64 var encodedBase64 = "VGhpcyBpcyBhIHNhbXBsZSB0ZXh0IGZvciBlbmNvZGluZw=="; var decodedbasevalue= ai.util.decodeBase64(encodedBase64); ai.log.logInfo("Decoded base64 is: "+decodedbasevalue); //Decoded base64 is:"This is a sample text for encoding" //Example for ai.util.encodeBase64 var rawBase64 = "This is a sample text for encoding"; var encodedbasevalue= ai.util.encodeBase64(rawBase64, ""); ai.log.logInfo("Encoded base64 is: "+encodedbasevalue); //Encoded base64 is:VGhpcyBpcyBhIHNhbXBsZSB0ZXh0IGZvciBlbmNvZGluZw== //Example for ai.util.encodeUrl var rawUrl = "https://docs.postman-echo.com/"; var encodedUrl=ai.util.encodeUrl(rawUrl); ai.log.logInfo("Encoded URL is: "+encodedUrl); //Encoded URL is: https%3a%2f%2fdocs.postman-echo.com%2f //Example for ai.util.decodeUrl var encodedUrl = "https%3a%2f%2fdocs.postman-echo.com%2f"; var decodedUrl=ai.util.decodeUrl(encodedUrl); ai.log.logInfo("Decoded URL is: "+decodedUrl); //Decoded URL is: https://docs.postman-echo.com/ //Example for ai.util.encrypt function testConnection(context) { var message = "-----BEGIN PGP MESSAGE-----" +"Version: GnuPG v2.0.14 (GNU/Linux)" +"Your Message" +"-----END PGP MESSAGE-----"; var text = ai.util.decrypt(message,'myPgp'); ai.log.logInfo("text message", text); return true; } //Example for ai.util.decrypt function testConnection(context) { var text = "Text to encrypt"; var encrypedPgpMessage = ai.util.encrypt(text,'myPgp'); ai.log.logInfo("encrypted message", encrypedPgpMessage ); return true; } //Example for ai.util.format var formatted=ai.util.format('How ar{0} you{1}',"e","?"); ai.log.logInfo("Formatted String is: "+formatted); //How are you? //Example for ai.util.isDate() var d = new Date(); var verifyIfDate=ai.util.isDate(d); ai.log.logInfo("Provided value is: "+verifyIfDate); //Provided value is: true //Example for ai.util.isUndefined var sampleValue; var verifyIfUndefined=ai.util.isUndefined(sampleValue); if (verifyIfUndefined) { ai.log.logInfo("Value is undefined"); } else { ai.log.logInfo("Value is defined"); } //Value is undefined //Example for ai.util.isDefined var sampleValue=6; var verifyIfDefined=ai.util.isDefined(sampleValue); ai.log.logInfo("verifyIfDefined: "+verifyIfDefined) if (verifyIfDefined) { ai.log.logInfo("Value is defined"); } else { ai.log.logInfo("Value is undefined"); } //Value is defined //Example for ai.util.isArray var sampleValue=["a","b"]; var verifyIfArray=ai.util.isArray(sampleValue); if (verifyIfArray) { ai.log.logInfo("Is is an Array"); } else { ai.log.logInfo("Not an Array"); } //It is an array //Example for ai.util.isString var sampleValue="123"; var verifyIfString=ai.util.isString(sampleValue); if (verifyIfString) { ai.log.logInfo("Is is a string"); } else { ai.log.logInfo("Not a string"); } //Example for ai.util.isNumber var sampleValue = {firstName:"Jon", lastName:"Doe"}; var verifyIfNumber=ai.util.isNumber(sampleValue); if (verifyIfNumber) { ai.log.logInfo("Is is a number"); } else { ai.log.logInfo("Not a number. Provided value is of type: "+typeof(sampleValue)); } //Not a number. Provided value is of type: object //Example for ai.util.isBoolean var sampleValue = true; var verifyIfBoolean=ai.util.isBoolean(sampleValue); if (verifyIfBoolean) { ai.log.logInfo("Value is Boolean"); } else { ai.log.logInfo("Not a Boolean. Provided value is of type: "+typeof(sampleValue)); } //Value is Boolean //Example for ai.util.isPrimitive var sampleValue = {firstName:"Jon", lastName:"Doe"}; var verifyIfPrimitive=ai.util.isPrimitive(sampleValue); if (verifyIfPrimitive) { ai.log.logInfo("Provided value is a Primitive Data Type"); } else { ai.log.logInfo("Provided value is not primitive: "+typeof(sampleValue)); } return true;