Defining structs
CRMScripts use immediate allocation. As with variables, methods must be declared before they are used. The definition has 3 parts:- keyword struct
- the name of the struct
- 1 or more statements enclosed in curly brackets, followed by a semi-colon
Using structs
From the outside, you create an instance of the struct and then you can use dot notation to access its variables and methods.- structName.methodName
- structName.variableName
Function chaining
Method chaining is a pattern where multiple functions are called on the same object consecutively. Using the same object reference, multiple functions can be invoked. It increases the readability of the code and means less redundancy.brand returns the current executing context back from the function call. The next function then executes on this context (referring to the same instance), and invokes the other functions associated with the struct.
Each of the functions returns the current execution context. The functions can be chained together because the previous execution returns results that can be processed further.
Built-in Methods
fromXMLNode
Populates a struct from an XMLNode. Only supports the following element datatypes:- Bool
- Float
- Integer
- String
- struct
For the types not supported natively by JSON, we will require/produce the following formats:
- Date: converted to/from string with format “YYYY-MM-DD”
- DateTime: converted to/from string with format “YYYY-MM-DDTHH:MI:SS”
- Time: converted to/from string with format “HH:MI:SS”
- Byte: converted to/from number.
String toJsonString()
This function will return a JSON formatted string of the struct’s contents. Same functionality as toJson(JSONBuilder), but it will return a string directly without having to instantiate a JSONbuilder. Introduced or updated in version: 10.1.4toJson
Populates a JSONBuilder from a struct. Only supports the following item datatypes:- Bool
- Float
- Integer
- String
- struct
For the types not supported natively by JSON, we will require/produce the following formats:
- Date: converted to/from string with format “YYYY-MM-DD”
- DateTime: converted to/from string with format “YYYY-MM-DDTHH:MI:SS”
- Time: converted to/from string with format “HH:MI:SS”
- Byte: converted to/from number.