string Functions
Use string functions in rules to manipulate text strings in asset JSON at runtime.
For instance, a string function can replace all occurrences of one string with another or convert strings from uppercase to lowercase. If a user enters a dashboard title in the wizard using all lowercase letters, the string function changes the text to sentence case at runtime.
toUpperCase
Parameters: Object object
Returns: Object
Recursive: Supported
Description: Converts all characters in an object to uppercase. The object can be a single string or a JSON object with multiple strings
Example
This sample JSON:
1 "objecttest" : {
2 "obj" : {
3 "greeting1" : "hello world" ,
4 "greeting2" : "salut world" ,
5 "greeting3" : "hallo world"
6 } ,
7 "list" : [ "hello world" , "salut world" , "hallo world" ]
8 }
And the rule:
1 {
2 "action" : "set" ,
3 "description" : "Convert all strings to upper case" ,
4 "path" : "$.objecttest" ,
5 "value" : "${string:toUpperCase(Rules.CurrentNode)}"
6 }
Returns:
1 "objecttest" : {
2 "obj" : {
3 "greeting1" : "HELLO WORLD" ,
4 "greeting2" : "SALUT WORLD" ,
5 "greeting3" : "HALLO WORLD"
6 } ,
7 "list" : [ "HELLO WORLD" , "SALUT WORLD" , "HALLO WORLD" ]
8 }
toLowerCase
Parameters: Object object
Returns: Object
Recursive: Supported
Description: Converts all characters in a string to lowercase.
Example
This sample JSON:
1 "objecttest" : {
2 "obj" : {
3 "greeting1" : "Hello World" ,
4 "greeting2" : "Salut World" ,
5 "greeting3" : "Hallo World"
6 } ,
7 "list" : [ "Hello World" , "Salut World" , "Hallo World" ]
8 }
And the rule:
1 {
2 "action" : "set" ,
3 "description" : "Convert all strings to lower case" ,
4 "path" : "$.objecttest" ,
5 "value" : "${string:toLowerCase(Rules.CurrentNode)}"
6 }
Returns:
1 "objecttest" : {
2 "obj" : {
3 "greeting1" : "hello world" ,
4 "greeting2" : "salut world" ,
5 "greeting3" : "hallo world"
6 } ,
7 "list" : [ "hello world" , "salut world" , "hallo world" ]
8 }
replace
Parameters: Object object, String oldStr, String newStr
Returns: Object
Recursive: Supported
Description: Returns a new object with all occurrences of oldStr replaced with newStr.
Example
This sample JSON:
1 "objecttest" : {
2 "obj" : {
3 "greeting1" : "Hello World"
4 } ,
5 "list" : [ "Hello World" ]
6 }
And the rule:
1 {
2 "action" : "set" ,
3 "description" : "Replace all Hello instances with Goodbye" ,
4 "path" : "$.objecttest" ,
5 "value" : "${string:replace(Rules.CurrentNode, 'Hello', 'Goodbye')}"
6 }
Returns:
1 "objecttest" : {
2 "obj" : {
3 "greeting1" : "Goodbye World"
4 } ,
5 "list" : [ "Goodbye World" ]
6 }
replaceAll
Parameters: Object object, String regex, String newStr
Returns: Object
Recursive: Supported
Description: Replaces all substrings of this string that match the given regular expression .
Example
This sample JSON:
1 "objecttest" : {
2 "obj" : {
3 "greeting1" : "Hello World"
4 } ,
5 "list" : [ "Hello World" ]
6 }
And the rule:
1 {
2 "action" : "set" ,
3 "description" : "Replace all 'l' instances with 'L'" ,
4 "path" : "$.objecttest" ,
5 "value" : "${string:replaceAll(Rules.CurrentNode, 'l.?', 'L')}"
6 }
Returns:
1 "objecttest" : {
2 "obj" : {
3 "greeting1" : "HeLLo WorLd"
4 } ,
5 "list" : [ "HeLLo WorLd" ]
6 }
replaceFirst
Parameters: Object object, String regex, String newStr
Returns: Object
Recursive: Supported
Description: Replaces the first substring of this string that matches the given regular expression .
Example
This sample JSON:
1 "objecttest" : {
2 "obj" : {
3 "greeting1" : "Hello World"
4 } ,
5 "list" : [ "Hello World" ]
6 }
And the rule:
1 {
2 "action" : "set" ,
3 "description" : "Replace the first 'l' instance with 'L'" ,
4 "path" : "$.objecttest" ,
5 "value" : "${string:replaceFirst(Rules.CurrentNode, 'l.?', 'L')}"
6 }
Returns:
1 "objecttest" : {
2 "obj" : {
3 "greeting1" : "HeLlo World"
4 } ,
5 "list" : [ "HeLlo World" ]
6 }
split
Parameters: Object object, String regex
Returns: Object
Recursive: Supported
Description: Parses a string and splits it into an array defined by the specified delimiter represented by the given regular expression .
Example
This function call:
1 ${string:split('one:two:three', ':')}
Results in array of strings:
match
Parameters: Object object, String regex
Returns: Object
Recursive: Supported
Description: Performs complex regular expression matching and returns an array of matching results.
Example
To capture items surrounded by square double quote and square brackets:
1 {
2 "match" : "${string:match('[ \" foo \" ][ \" bar \" ][ \" baz \" ]', ' \\ [ \\\" (.*?) \\\"\\ ]')}"
3 }
Returns the following array:
1 {
2 "match" : "[ \" foo \" , \" bar \" , \" baz \" ]"
3 }
join
Parameters: Object object, String delimiter
Returns: Object
Recursive: Supported
Description: Creates a string from an array of strings and separates each item by the specified delimiter.
Example
This function call:
1 ${string:join(['foo','bar','baz'], ':')}
Results in:
qualifyNamespace
Parameters: String name
Returns: String
Recursive: Not supported
Description: Adds a Salesforce namespace and the __ delimiter to a given name if a namespace is available. If there is no namespace, the name is returned without alteration.
Example
This sample JSON:
1 {
2 "fieldName" : "myName"
3 }
With:
1 "${string:qualifyNamespace(Variables.fieldName)}"
Returns:
1 {
2 "fieldName" : "myNamespace__myName"
3 }
hash
Parameters: Object object, int length
Returns: Object
Recursive: Supported
Description: Returns the hash value for the given string. Useful for determining Salesforce ID lengths and uniqueness. Uses the SHA-256 algorithm to determine the hash value.
Example
This function call returns a truncated hash value:
1 {
2 "hash" : "${string:hash('00D000000000001EAA', 5)}"
3 }
Results in: