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.

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

Methods

getBlockExecution()

Checks whether the current event action has been blocked.

Declaration

Bool getBlockExecution()

Returns

Type Description
Bool

getInputValue(String)

Returns the value of a specified input field (for example "ContactEntity.Department").

Declaration

String getInputValue(String field)

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();
}

Parameters

Type Name Description
String field

Returns

Type Description
String The value of the field.

getInputValues()

Returns a Map containing all input values of the EventData object.

Declaration

Map getInputValues()

Examples

EventData ed = getEventData();
Map m = ed.getInputValues();

m.first();
while (!m.eof()){
  printLine(m.getKey() + " = " + m.getVal());
  m.next();
}

Returns

Type Description
Map All input values of the object.

getMessage()

Returns the message set in an EventData object.

Declaration

String getMessage()

Examples

EventData ed = getEventData();
printLine(ed.getMessage());

Returns

Type Description
String The message set in the object.

getNavigateTo()

Returns the section EventData has navigated to.

Declaration

String getNavigateTo()

Returns

Type Description
String

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

getStateValues()

Returns a Map containing all state values of the EventData object (custom values).

Declaration

Map getStateValues()

Returns

Type Description
Map

getType()

Returns the integer representing the event type.

Declaration

Integer getType()

Examples

EventData ed = getEventData();
printLine(ed.getType().toString());

Returns

Type Description
Integer

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

setMessage(String)

Displays a dialog box containing the specified message.

Declaration

Void setMessage(String message)

Examples

EventData ed = getEventData();
String orgNr = ed.getInputValue("ContactEntity.OrgNr");
if(orgNr.isEmpty()) {
  ed.setMessage("Please type an Org.Nr");
}

Parameters

Type Name Description
String message

Returns

Type Description
Void

setNavigateTo(String)

Sets which page to load next. For example, "sale.main".

Declaration

Void setNavigateTo(String url)

Examples

EventData ed = getEventData();
ed.setNavigateTo("soprotocol:sale.document?document_id=0");

Parameters

Type Name Description
String url

Returns

Type Description
Void

setOutputValue(String,String)

Sets the value of a specified output field (for example "ContactEntity.Department").

Declaration

Void setOutputValue(String name, String value)

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) + "]");
}

Parameters

Type Name Description
String name
String value

Returns

Type Description
Void

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

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)

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) {
  // ...
}

Parameters

Type Name Description
String message

Returns

Type Description
Void

showDialog(EventDataDialogDefinition)

Triggers a dialog to handle user input.

Declaration

Void showDialog(EventDataDialogDefinition dialog)

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);

Parameters

Type Name Description
dialog Dialog definition

Returns

Type Description
Void