Recently I was asked to create a method directive on the jobEntry.Update method that needed to ask the user whether they wanted to send an email to a party.
This is pretty straightforward in a customization, using the MessageBox.Show built, however, due to BPM’s running on the server, System.Windows.Forms cannot be referenced and MessageBox cannot be used in BPM custom code.
This post details the solution I came up with, using the ‘Call BPM Data Form’ caller from within the ‘BPM Workflow Designer’
I have kept it as simple as possible so, the workflow fires on checking of the ‘Unfirm’ checkbox’ and displays either the message ‘Cancel’ or the message ‘OK’ depending on which button is pressed.
- Select ‘Method Directive Maintenance’ from the menu.
- Select ‘Method Code’ of ‘JobEntry’.
- Select the ‘Update’ directive.
- Click on the ‘PreProcessing’ tab and then ‘Select ‘New Pre Processing’ from the menu bar.
- Give the new directive a name. I called mine ‘Test Dialog’.
- Click on the ‘Design’ button to invoke the workflow designer.
- Create a condition to check whether the ‘Unfirm’ checkbox has been changed
- Drag in the ‘Call BPM Data Form’ from the callers section and join it to the ‘True’ branch of the ‘Enable Firm’ condition.
- We now need to build the dialog box by clicking on the ‘BPM data form’ item
- Click on the ‘named’ link in the ‘actions’ section.
- Click on the ‘Run Designer’ button.
- Once the designer has been invoked you will see any data form you have already created. In this case we want to create a new one, so select ‘New Form’ from the menu bar
- Call the form YesNoBase and give it a title of ‘Simple Dialog’ example.
- We now need to design the dialog box
- Click on the fields tab and select ‘New Button’ from the menu bar. The button will default with the OK button. Enter ‘Cancel’ in the label for 1112. The values ‘1111’ and ‘1112 are important as these are the ones you will use to interpret the user response
- Your form is now ready, so you can test it from the ‘Actions -> Test BPM Data Form’ menu
- Save the form and close down the ‘BPM Data Form Designer’.
- Select the ‘YesNoBase’ form in the ‘Actions’ part of the ‘Call BPM Data Form’ caller.
- We are now going to add a condition to the BPM that will return a message of ‘OK’ if the user presses the ‘OK’ button and ‘Cancel’ if the user presses the ‘Cancel’ button.
- Add the condition to the BPM and join the data form caller to the condition
- Call the Condition ‘Test OK/ Cancel’
- Add the condition ‘The specified call context field is equal to the specified expression.
- Change the ‘specified call context field’ to ‘Button Value’
- Change the ‘specified expression’ to 1111 which the value returned when the user selects OK.
- Add a message to the true branch that displays ‘OK’ and a message to the ‘False’ branch’ that displays cancel.
- Finally, add an exception to the ‘Cancel’ branch, so that the ‘Firming of the job doesn’t occur.
- Press the ‘Save and Exit’ button
- Check the ‘Enabled’ box in the method directive form.
- Save the directive
- To test this you need to have an unfirm job opne in the ‘Job Entry screen.
- Click on the ‘Unfirm’ checkbox and the dialog box will appear
- Press ‘Cancel’ and the message that you entered for the ‘Cancel’ branch appears and most importantly the exception is called and the job is not formed.
- Press ‘OK’ and the message attached the ‘OK’ branch appears and the job is firmed
It is worth noting that BPM data fors can be customised, so you can tailor the dialog box to your specific needs.
Hope that helps – as ever please let me have your feedback.