Adding the BadCreateAccount Rule

The BadCreateAccount rule has a higher priority, so it will fire before the CreateAccount rule.

Procedure

  1. Right-click the Rules folder, and select New > Rule.
    You will see the New Rule Wizard.
  2. In the Rule name field, type BadCreateAccount.
    In the Description field, type Checks for an existing account with the specified ID.
  3. Click Finish.
  4. In the Form tab, set the Priority field to 3.
    This is a higher priority than 5, the default. You’ll set the CreateAccount rule to priority 5, so that the BadCreateAccount rule always fires before CreateAccount rule.
  5. Expand the Declaration section as needed so you can see empty rows below the headings Term and Alias.
    Each of the sections can be expanded and contracted as needed.
  6. Drag the Account concept from the TIBCO BusinessEvents Studio Explorer tree into the first empty row in the Declaration section.
    You will see the project path of the Account concept in the Term column, and account in the Alias column.
  7. Similarly, drag the CreateAccount event into the next available row.
    Declaration
     The Declaration provides the scope of the rule. It lists all the entity types to be used in the rule, and their aliases. By default the alias is set to the entity name in lower case letters. You can change it as desired.
  8. In the Conditions panel, type the following:
    //Checks whether the extId of an Account instance in working memory //matches the incoming event's account ID account@extId == createaccount.AccountId;

    Notice that when you type the At sign (@), a pick list of concept attributes appears. Attributes are built-in. You cannot add or remove attributes. The id attribute value is set internally. However you can set the external ID, extId.

  9. In the Actions panel, just below the Conditions panel, type these statements:
    System.debugOut("#### Account already exists: " + createaccount.AccountId);
    Event.consumeEvent(createaccount);

    These actions are done only if the conditions are met. If not, then the next rule in the agenda fires — and that is likely to be the CreateAccount rule, which you’ll define next.

    You are also consuming the event, so it cannot trigger any other rules.

  10. Save and close the resource.