Sample Scenario 8: Voting for Various Choices

In this scenario, you need several managers at the same level to approve an engineering change, by means of a response to a message. So, you must send a notification that prompts the managers for a response. If at least two of the managers send responses approving the change, you then approve the requested change in the application.

For this scenario:

  • Assume that global constants are created for EngineeringMgr, ProjectMgr, and ProgramMgr.

    The creation of global constants is described in previous scenarios.

  • Use the IdoOnItemInsert framework event.

To accomplish this scenario:

  1. Create and save an event handler with these settings:
    Event Name

    Select IdoOnItemUpdate.

    Applies to Objects

    Specify SLECNs.

    Description
    Specify ECN Approval.
  2. Create one action, which sends a prompt to the managers requesting a response:
    1. On the Event Actions form, specify this information:
      Action Sequence

      Specify 10.

      Action Type

      Select Prompt.

    2. Use the Event Action Prompt form and associated event action parameter forms to create these parameters:
      TO
      Specify GC(EngineeringMgr) + ';' +GC(ProjectMgr) + ';' +GC(ProgramMgr).
      SUBJECT
      Specify SUBSTITUTE("Need approval for engineering change {0}, {1}", P("EcnNum"), P("ReasonCodeDescription")).
      CATEGORY
      Specify "Engineering".
      BODY
      Specify "Please review the proposed engineering change on the Variables tab. Then use the Approve or Reject buttons on the Response tab to register your response."
      SAVEMESSAGE
      Specify FALSE.
      QUESTION
      Specify To approve or reject, click the buttons below.
      CHOICES
      Specify 1,sApprove, 0,sReject.
      VOTINGRULE
      Specify Minimum Count Preferred Choice.
      PREFERREDCHOICE
      Specify 1.
      MINIMUM
      Specify 2.
      FILTERFORM
      Specify EngineeringChangeNotices.
      FILTER
      Specify SUBSTITUTE("ECNNum={0}", FP("ECNNum")).
    3. Save the action.
      If you have done everything correctly, your syntax for this action step should look like this:
      TO('' + GC(EngineeringMgr) + ';' + GC(ProjectMgr) + ';' + GC(ProgramMgr))
      CATEGORY("Engineering")
      SUBJECT(SUBSTITUTE("Need approval for engineering change {0}, {1}", P("EcnNum"), P("ReasonCodeDescription")))
      BODY("Please review the proposed engineering change on the Variables tab. Then use the Approve or Reject buttons on the Response tab to register your response.") 
      SAVEMESSAGE(FALSE)
      QUESTION("To approve or reject, click the buttons below.")
      CHOICES("1,sApprove,0,sReject") VOTINGRULE(MinimumCountPreferredChoice) 
      MINIMUM(2)
      PREFCHOICE("1") 
      FILTERFORM("EngineeringChangeNotices") 
      FILTER(SUBSTITUTE("ECNNum={0}", FP("ECNNum")))
  3. Create the second action, which tells the system how to respond if approval is not granted:
    1. On the Event Actions form, specify this information:
      Action Sequence

      Specify 20.

      Action Type

      Select Fail.

    2. Starting with the Event Action Fail form, use the associated forms to create these parameters:
      • CONDITION(VOTINGRESULT(10) = "0")
      • RESULT("The ECN change request was rejected by the managers.")
    3. Save the action.
    4. Close the Event Actions form.
  4. Return to the Event Handlers form and select the Suspend check box.
  5. Save the handler.
  6. Discard the cached metadata.
  7. Test the event handler:
    1. Open the Engineering Change Notices form.
    2. Update an existing ECN and click Save.
      After you save the ECN, when the Engineering Change Notices form is refreshed, the record should be disabled for updating. This form remains read-only until the ECN has been approved.
    3. Optionally, select Actions > View Event Status.
    4. On the Event Status form, navigate to the last row and verify that the status for this event is Running.
    5. Open the Inbox form for the individual designated as the Engineering Manager.
    6. Verify that the message is received and that the Response tab displays the question and choice buttons.
    7. Click the Yes button.
    8. Open the Inbox form for the individual designated as the Project Manager.
    9. Verify that the message is received and that the Response tab displays the question and choice buttons.
    10. Click the Yes button.
    11. Refresh the collection on the Engineering Change Notices form.
    12. Verify that the ECN now displays normally (read/write) and shows your changes.
      As soon as two managers vote for the preferred choice, voting is closed and the change is approved. The third manager's vote is not needed.

You can also do a second test by clicking the No button to reject the request by all three managers. In this case, when you refresh the Engineering Change Notices form, the ECN record displays normally but your changes are gone.

When creating this event handler, keep these points in mind:

  • When creating a message that requires a response from the recipient, usually a Prompt action type, you must mark the handler so that it suspends when executed. This means that it is also automatically marked as a synchronous handler.
  • Because these event handlers must be suspended, pending the managers' responses, the Framework Event Service must be enabled for the configuration in which you are logged on.