Skip to main content

Entity Events and Business Commands

Create a Change Log

Business commands are very useful when you want to interact with your data. You can define Entity events to set conditions for when to trigger your commands. This section will create a simple change log to show all of the changes made to the Title of the Support Tickets by users.

NOTE: This tutorial is built upon the foundation of the Support Ticket application.

1. Create Log Entity

First, we need to create the entity where we will store all the logs.

  • Type: Ctrl + Shift + C and click Entity
  • Set Name to: Log
  • Set the Display Icon (if necessary).
  • Mark the Create Display Attribute check circle. Type Title Change
  • Click Next
  • Remove the Create page and Detail Page. Keep the List Page
  • Click Finish
  • Go to Data > Entities and click Ticket
  • Click Add New Reference
  • Set Reference Type to: Composition
  • Set Target to: Log
  • Click Create References

2. Update Entity pages

Next, all logs should show for each entity.

  • Go to UI > Entity Pages and click Ticket Detail
  • Go the Layout section, and click the Add Tab magic wand (near the bottom of the page).
  • Select Create Child List Tab. (Make sure that all files are saved so that the proper options will be available.)
  • Select Logs
  • Click the Logs tab.
  • Hover over the lower section of the Layout screen. Click Edit Layout
  • Locate the DataGrid of Log and click Configure DataGrid
  • On the General tab, Label can be added, but it may be unnecessary since the tab has its own title.
  • Verifty that Entity is set to: Log
  • Verify that Data Source is set to: (ticket, db, ctx) => db.LogSet.Where(x => x.Ticket == ticket)
  • Click the Columns tab
  • Log is automatically shown. Add Ticket
  • Click OK
  • Click OK
  • Save: Ctrl + S

3. Create Business command

A command needs to be added to pull the log into the list.

  • Type: Ctrl + Shift + C and in the Business section, select Command
  • Set Name to: Log Title Change
  • Set Type to: Entity Command
  • Set Entity to: Ticket
  • Click Finish
  • Copy and paste the following code:
(ticket, db, ctx) =>
{
ticket.Logs.Add(new Log()
{
TitleChange = "Title changed at: " + DateTime.Now.ToString() + " - New Title: " + (string.IsNullOrEmpty(ticket.Title) ? "no title defined!" : ticket.Title)
});
}
  • Save: Ctrl + S

4. Create Event Entity

The trigger for data to be added to the Change Log is when an end user alters the title of a Support Ticket.

  • Type: Ctrl + Shift + C and in the Business section, select Business Events.
  • Set Command to: LogTitleChange (Ticket)
  • Click Finish
  • On the Event Triggers page, select the appropriate allocations. For example, for Entity Ticket mark “Created” and for Attribute Changes – Title mark “Changed”
  • Save: Ctrl + S