Class 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.Syntax
Examples
EventData ed = getEventData();
Map sourceIds;
sourceIds.insert("11", "");
sourceIds.insert("128", "");
sourceIds.insert("135", "");
if (sourceIds.exists(sourceId.toString())){
// ...
}
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");
}
Constructors
EventData()
Initializes a new instance of the EventData class.
Declaration
EventData
Examples
EventData ed = getEventData();
Map sourceIds;
sourceIds.insert("11", "");
sourceIds.insert("128", "");
sourceIds.insert("135", "");
if (sourceIds.exists(sourceId.toString())){
// ...
}
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");
}
Methods
getBlockExecution()
Checks whether the current event action has been blocked.
Declaration
Bool getBlockExecution()
Returns
Type | Description |
---|---|
Bool |
Examples
EventData ed = getEventData();
Map sourceIds;
sourceIds.insert("11", "");
sourceIds.insert("128", "");
sourceIds.insert("135", "");
if (sourceIds.exists(sourceId.toString())){
// ...
}
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");
}
getInputValue(String)
Returns the value of a specified input field (for example "ContactEntity.Department").
Declaration
String getInputValue(String field)
Parameters
Type | Name | Description |
---|---|---|
String | field |
Returns
Type | Description |
---|---|
String | The value of the field. |
Remarks
Use Trace to discover the name of the input value you want to fetch.
Examples
EventData ed = getEventData();
Integer projectId = ed.getInputValue("ProjectEntity.ProjectId").toInteger();
Bool isCompleted = ed.getInputValue("ProjectEntity.Completed").toBool();
EventData ed = getEventData();
String listId = ed.getInputValue("SaleEntity.UserDefinedFields.SuperOffice:1").after(":").before("]");
if(listId != ""){
NSMDOAgent agent;
NSMDOListItem item = agent.GetListItem("udlist99", listId.toInteger());
String listName = item.GetName();
}
getInputValues()
Returns a Map containing all input values of the EventData object.
Declaration
Map getInputValues()
Returns
Type | Description |
---|---|
Map | All input values of the object. |
Examples
EventData ed = getEventData();
Map m = ed.getInputValues();
m.first();
while (!m.eof()){
printLine(m.getKey() + " = " + m.getVal());
m.next();
}
getMessage()
Returns the message set in an EventData object.
Declaration
String getMessage()
Returns
Type | Description |
---|---|
String | The message set in the object. |
Examples
EventData ed = getEventData();
printLine(ed.getMessage());
getNavigateTo()
Returns the section EventData has navigated to.
Declaration
String getNavigateTo()
Returns
Type | Description |
---|---|
String |
Examples
EventData ed = getEventData();
Map sourceIds;
sourceIds.insert("11", "");
sourceIds.insert("128", "");
sourceIds.insert("135", "");
if (sourceIds.exists(sourceId.toString())){
// ...
}
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");
}
getStateValue(String)
Returns the value of a specified state field (custom field).
Declaration
String getStateValue(String stateValue)
Parameters
Type | Name | Description |
---|---|---|
String | stateValue |
Returns
Type | Description |
---|---|
String |
Examples
EventData ed = getEventData();
Map sourceIds;
sourceIds.insert("11", "");
sourceIds.insert("128", "");
sourceIds.insert("135", "");
if (sourceIds.exists(sourceId.toString())){
// ...
}
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");
}
getStateValues()
Returns a Map containing all state values of the EventData object (custom values).
Declaration
Map getStateValues()
Returns
Type | Description |
---|---|
Map |
Examples
EventData ed = getEventData();
Map sourceIds;
sourceIds.insert("11", "");
sourceIds.insert("128", "");
sourceIds.insert("135", "");
if (sourceIds.exists(sourceId.toString())){
// ...
}
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");
}
getType()
Returns the integer representing the event type.
Declaration
Integer getType()
Returns
Type | Description |
---|---|
Integer |
Examples
EventData ed = getEventData();
printLine(ed.getType().toString());
setBlockExecution(Bool)
Prevent the current event action from being executed.
Declaration
Void setBlockExecution(Bool value)
Parameters
Type | Name | Description |
---|---|---|
Bool | value |
Returns
Type | Description |
---|---|
Void |
Examples
EventData ed = getEventData();
Map sourceIds;
sourceIds.insert("11", "");
sourceIds.insert("128", "");
sourceIds.insert("135", "");
if (sourceIds.exists(sourceId.toString())){
// ...
}
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");
}
setMessage(String)
Displays a dialog box containing the specified message.
Declaration
Void setMessage(String message)
Parameters
Type | Name | Description |
---|---|---|
String | message |
Returns
Type | Description |
---|---|
Void |
Examples
EventData ed = getEventData();
String orgNr = ed.getInputValue("ContactEntity.OrgNr");
if(orgNr.isEmpty()) {
ed.setMessage("Please type an Org.Nr");
}
setNavigateTo(String)
Sets which page to load next. For example, "sale.main".
Declaration
Void setNavigateTo(String url)
Parameters
Type | Name | Description |
---|---|---|
String | url |
Returns
Type | Description |
---|---|
Void |
Examples
EventData ed = getEventData();
ed.setNavigateTo("soprotocol:sale.document?document_id=0");
setOutputValue(String,String)
Sets the value of a specified output field (for example "ContactEntity.Department").
Declaration
Void setOutputValue(String name, String value)
Parameters
Type | Name | Description |
---|---|---|
String | name | |
String | value |
Returns
Type | Description |
---|---|
Void |
Examples
Integer newOrgNr = 987654321;
EventData ed = getEventData();
ed.setOutputValue("ContactEntity.OrgNr", newOrgNr);
EventData ed = getEventData();
String projectId = ed.getInputValue("ProjectEntity.ProjectId");
SearchEngine se;
se.bypassNetServer(true);
se.addField("sale.amount", "sum");
se.addCriteria("sale.project_id", "Equals", projectId);
if(se.select() > 0) {
ed.setOutputValue("ProjectEntity.UserDefinedFields.SuperOffice:1", "[F:" + se.getField(0) + "]");
}
setStateValue(String,String)
Sets a state value that can be accessed later, also by other EventData objects in the same script (custom value).
Declaration
Void setStateValue(String stateName, String val)
Parameters
Type | Name | Description |
---|---|---|
String | stateName | |
String | val |
Returns
Type | Description |
---|---|
Void |
Examples
EventData ed = getEventData();
Map sourceIds;
sourceIds.insert("11", "");
sourceIds.insert("128", "");
sourceIds.insert("135", "");
if (sourceIds.exists(sourceId.toString())){
// ...
}
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");
}
setValidationMessage(String)
A shorthand for calling setBlockExecution(true) and setMessage(message).
It allows you to block a save and set a response message in a single function call.Declaration
Void setValidationMessage(String message)
Parameters
Type | Name | Description |
---|---|---|
String | message |
Returns
Type | Description |
---|---|
Void |
Examples
EventData ed = getEventData();
if(ed.getInputValue("x_invoice_no.value") == "") {
getHtmlElement("x_invoice_no").setErrorMessage("Error");
ed.setBlockExecution(true);
}
String orgNr = ed.getInputValue("ContactEntity.OrgNr");
if(orgNr.isEmpty()) {
ed.setValidationMessage("Please type in a Org.Nr");
}
else if(!orgNr.isDigit() || orgNr.getLength() != 9) {
// ...
}
showDialog(EventDataDialogDefinition)
Triggers a dialog to handle user input.
Declaration
Void showDialog(EventDataDialogDefinition dialog)
Parameters
Type | Name | Description |
---|---|---|
dialog | Dialog definition |
Returns
Type | Description |
---|---|
Void |
Examples
EventData ed = getEventData();
EventDataDialogDefinition dialog;
dialog.setTitle("My dialog title");
dialog.setType("okcancel");
dialog.setIcon("info");
dialog.setWidth(200);
dialog.setHeight(200);
dialog.setPrefix("step1_");
dialog.setText("My body text");
ed.showDialog(dialog);