EventData
EventData gives you access to contextual information in an event handler. For example, the name of a created company or the amount of a sale.
You can also check EventData
properties after the event handler has run, to for example display a message or prevent an entity from being saved.
Example
Check if a sale has a high enough value. Return a message and block the sale for values < 100. Set for the event "Before save sale".
EventData ed = getEventData();
if (ed.getInputValue("SaleEntity.Amount").toInteger() < 100)
{
ed.setBlockExecution(true); // Prevents save
ed.setMessage("Amount too low");
}
Fetch variables used in the current context
EventData ed = getEventData();
Note
EventData doesn't work with manually run scripts!
Type
The types of events that can occur pertain to either Service screen events (beforeSetFromCgi
, afterSetFromCgi
, beforePrint
) or triggers.
- Integer getType()
Input values
Input values are for getting available data - a read operation. You can either fetch a specific value or a Map with all values.
- String getInputValue(String inputValue)
- Map getInputValues()
Output values
Output values are for setting (or changing) data - a write operation. They are frequently set on a before save trigger to get better data quality.
Custom values
In addition to the built-in input and output values, you can also set and get custom values. These are also called state values and work just like setting and getting the standard values. The only difference is that naming the custom variables is up to you.
Method | Description | Equivalent to |
---|---|---|
getStateValue | Get specific value | getInputValue |
getStateValues | Get all values | getInputValues |
setStateValue | Set specific value | setOutputValue |
After you set a custom value, it can be accessed - also by other EventData
objects in the same script.
Open dialog to handle user interaction
Note
From version 10.1.9 we support generating a dialog from CRMScript triggers in Sales client.
In certain scenarios, it can be necessary to ask the user for input or confirmation before completing process, using this method we allow for creating a simple dialog which will return input back to CRMScript trigger. Use this to construct a useful workflow.
Messages
- String getMessage()
- Void setMessage(String message)
Validation and blocking actions
- Bool getBlockExecution()
- Void setBlockExecution(Bool value)
- Void setValidationMessage(String message)
Setting criteria with a Map instead of multiple OR conditions in an if statement
Map sourceIds;
sourceIds.insert("11", "");
sourceIds.insert("128", "");
sourceIds.insert("135", "");
if (sourceIds.exists(sourceId.toString())){
// ...
}
Navigation
Navigation uses SOProtocol and URL parameters.
- String getNavigateTo()
- Void setNavigateTo(String url)