Вы находитесь на странице: 1из 131

2013. All rights reserved.

Murray Fife
Microsoft MVP, Dynamics AX
2013. All rights reserved.
PREFACE
There are a lot of workflow templates that are delivered with Dynamics AX 2012, but that doesnt mean that those are the only ones that you can use. Developing new workflow templates
and actions are pretty straight forward and you can easily extend out the system to incorporate other workflow scenarios that have not been added yet.
In this worked example we will work through one example and show you how you can develop your own workflow process for product approvals that allow you to submit, track and
approve the product review process.
WHAT YOU NEED FOR THIS BLUEPRINT
All the examples shown in this blueprint were done with the Microsoft Dynamics AX 2012 virtual machine image that was downloaded from the Microsoft CustomerSource or PartnerSource
site. If you don't have your own installation of Microsoft Dynamics AX 2012, you can also use the images found on the Microsoft Learning Download Center. The following list of software
from the virtual image was leveraged within this blueprint:
Microsoft Dynamics AX 2012 (both R1 and R2)
Even though all the preceding software was used during the development and testing of the recipes in this book, they may also work on earlier versions of the software with minor tweaks
and adjustments, and should also work on later versions without any changes.
ERRATA
Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our booksmaybe a mistake in the text or the codewe
would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please
report them by emailing murray@murrayfife.me.
PIRACY
Piracy of copyright material on the Internet is an ongoing problem across all media. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with
the location address or website name immediately so that we can pursue a remedy.
Please contact us at murray@murrayfife.me with a link to the suspected pirated material.
We appreciate your help in protecting our authors, and our ability to bring you valuable content.
QUESTIONS
You can contact us at murray@murrayfife.me if you are having a problem with any aspect of the book, and we will do our best to address it.
2013. All rights reserved.
ADDITIONAL RESOURCES
Sometimes the image quality has not been the best because SlideShare compresses the images when they are uploaded, and also it moving fromslide to slide can
sometimes be a little slow, and with the larger slide decks this can be frustrating especially if you are looking for some particular content. Here are some additional
locations that you can find the blueprint contents:
ON AMAZON
We have created reference Blueprints that are available on Amazon that combine all of the information in the SlideShare post into an easy to reference and lightweight
format. These should be better references when working through some of the more intricate or lengthy posts, and also should give you better access to the content
and code snippets. These take a little bit of time to develop and publish, but I should be creating these as part of the documentation process, but they give me the
ability to update them continually, and also add additional notes and sections that you will be able to access automatically through the Kindle publishing process, so not
all of the blueprints are available in this format, but were working on it. View the Blueprint on Amazon here:
http://www.amazon.com/Murray-Fife/e/B00G9CNJPQ
THROUGH BLOGS
Also we have posted a most of the individual posts on the Extending Dynamics AX blog. If you ware looking for a quick link to grab a code snippet from, or to
reference a particular process, then you can find them here:
http://www.extendingdynamicsax.com
Also, there are a lot of smaller posts that we make showing tips that you might find useful. For those we have created another blog called Dynamics AX Tip Of The Day.
As you may have probably guessed there should be a new post every work day. You can find this blog here:
http://www.dynamicsaxtipoftheday.com
ON FACEBOOK
If you want an easy way to track the posts on all of the channels that I am using, then make sure you follow the Facebook page that we have created:
http://www.facebook.com/extendingdynamicsax
2013. All rights reserved.
Introduction
There are a lot of workflow templates that are delivered with Dynamics AX 2012, but that
doesnt mean that those are the only ones that you can use. Developing new workflow
templates and actions are pretty straight forward and you can easily extend out the system
to incorporate other workflow scenarios that have not been added yet.
In this worked example we will work through one example and show you how you can
develop your own workflow process for product approvals that allow you to submit, track
and approve the product review process.
The following topics that are included in this blueprint:
1. Create a New Development Project for your Workflow Development
2. Create a Menu Item for the Product Management Workflows
3. Add the Workflow Editor Menu Item to the Product Area Page
4. Create a New Workflow Category for Your Product Management Workflows
5. Create a Base Enumeration to Track the Approval Status
6. Add the Approval Status Field to the Product Table
7. Adding the Approval Status to the Released Products Form
8. Add a canSubmitToWorkflowMethod to the Table to Enable Workflows
9. Create a Query on the Products Table for the Workflows to Reference
10. Create a Workflow Type Using the Workflow Wizard
11. Create A Simple Product Approval Workflow
12. Enabling Workflow Submission on the Product Details Form
13. Updating the Submission Manager Method to Start the Workflow
14. Relabel the Workflow Submission Menu Items
15. Update the Completed Method on the Approval Event Handler
16. Using the Tutorial Workflow Processor to Process Workflows
17. Configuring the Workflow Processors to Run Automatically (Kindle)
18. Creating a Class to Manually Run Workflow Processes (Kindle)
19. Performing the Workflow Approval through the Dynamics AX Forms
20. Creating a New Product Approval Workflow Task Element (Kindle)
21. Relabeling the Approval Action Menu Item Labels (Kindle)
22. Update the Workflow Approval Element Event Handlers (Kindle)
23. Add the Product Approval Element to the Workflow Template (Kindle)
24. Using the Product Approval Element in the Approval Workflow (Kindle)
25. Performing Product Approval Using the Custom Approval Element (Kindle)
2013. All rights reserved.
CREATE A NEW DEVELOPMENT PROJECT FOR
YOUR WORKFLOW DEVELOPMENT
Before we start we need to quickly create a project that we can use to store all of the tweaks that we will be making to the system in order to start off out new workflow development. This
will allow us to keep all of our development segregated out, and also make it easier to move the changes over to other environments if we want to.
In this section we will show how to create a new project for our Workflow development.
2013. All rights reserved.
Create a New
Development
Project for your
Workflow
Development
Start off by opening up an AOT session.
2013. All rights reserved.
Create a New
Development
Project for your
Workflow
Development
Open up the Projects explorer either by clicking on the
Projects icon in the menu bar, or by pressing
CTRL+SHIFT+P.
2013. All rights reserved.
Create a New
Development
Project for your
Workflow
Development
Then the projects menu is displayed, right-mouse-click on
the Private folder, and select the Project option from the
New submenu.
2013. All rights reserved.
Create a New
Development
Project for your
Workflow
Development
This will create a new project for you.
2013. All rights reserved.
Create a New
Development
Project for your
Workflow
Development
Change the project name to something a little more
understandable (ProductManagementworkflows) either
in the Properties window, or direct in the Projects
explorer tree.
2013. All rights reserved.
Create a New
Development
Project for your
Workflow
Development
Finally, double-click on the new project that you created
to open up the project by itself within the development
workspace.
2013. All rights reserved.
CREATE A MENU ITEM FOR THE PRODUCT
MANAGEMENT WORKFLOWS
In this scenario, there is no menu item on the Product information management area page that allows you to maintain workflows, so we will start by creating a menu item for the product
workflows which we will then add to the menu in the next step.
In this example we will show how to create a new menu item for the workflow editor that we can use on the Product information management area page.
2013. All rights reserved.
Create a Menu Item
for the Product
Management
Workflows
From within the workflow development project, right-
mouse-click on the parent folder, and from the New
menu, select Menu Itemand then Display to create a new
display menu item.
2013. All rights reserved.
Create a Menu Item
for the Product
Management
Workflows
Change the Name of the menu item to
WorkflowConfigurationProducts and change the Label to
be Product information management workflows.
2013. All rights reserved.
Create a Menu Item
for the Product
Management
Workflows
Change the Object property to WorkflowTableListPage to
link the menu item to the workflow list page.
2013. All rights reserved.
Create a Menu Item
for the Product
Management
Workflows
Then change the EnumTypeParameter to ModuleAxapta
and the EnumParameter to Inventory.
2013. All rights reserved.
Create a Menu Item
for the Product
Management
Workflows
Once you have done that, save the project to commit the
changes, and also to make sure that there werent any
errors in the updates.
2013. All rights reserved.
ADD THE WORKFLOW EDITOR MENU ITEM TO
THE PRODUCT AREA PAGE
Once you have the menu item, you can add it to the Product information management area page so that you can use it.
In this example we will show how to add your new menu item to the menus.
2013. All rights reserved.
Add the Workflow
Editor Menu Item to
the Product Area
Page
Open up the AOT workspace so that you have both the
Workflow Project and the AOT tree displayed.
Within the AOT tree, open up the Menus group and find
the ProductInformationManagement menu.
2013. All rights reserved.
Add the Workflow
Editor Menu Item to
the Product Area
Page
Drag the ProductInformationManagement folder over
from the AOT tree to the parent level of the
ProductManagementWorkflows project tree.
Note: You should be able to expand the copy of the menu
up and see all of the details including the Setup group
where we want to put the menu item for the workflow
editor.
2013. All rights reserved.
Add the Workflow
Editor Menu Item to
the Product Area
Page
Drag the WorkflowConfigurationProducts menu item up
into the Setup folder of the menu.
Note: This will probably drop it at the bottom of the
menu. Just select it and use the ALT+UPARROW to
quickly move it under the parameters menu item.
After you have done that, save your project to make sure
that you didnt introduce any errors.
2013. All rights reserved.
Add the Workflow
Editor Menu Item to
the Product Area
Page
Now if you open up the Product information
management area page you will be able to see the
workflow editor menu item.
2013. All rights reserved.
CREATE A NEW WORKFLOW CATEGORY FOR
YOUR PRODUCT MANAGEMENT WORKFLOWS
Now that we have the editor in the right place, we can start building our framework for the workflows themselves. The first step is to create a Workflow Category to store all of our new
workflows against.
In this example we will show how you can create a new Workflow Category.
2013. All rights reserved.
Create a New
Workflow Category
for Your Product
Management
Workflows
From within the workflow development project, right-
mouse-click on the parent folder, and from the New
menu, select Workflow and then Workflow Category to
create a new category for your workflows.
2013. All rights reserved.
Create a New
Workflow Category
for Your Product
Management
Workflows
Change the Name of the workflow category to
ProductManagementWFCategory and change the Label
to be Product information management workflows.
2013. All rights reserved.
Create a New
Workflow Category
for Your Product
Management
Workflows
Change the Module parameter to Inventory.
Note: This is the same as the EnumParameter of the
workflow editor that we just created which tells the editor
to use the workflows that are assigned this category.
2013. All rights reserved.
Create a New
Workflow Category
for Your Product
Management
Workflows
When you have done that, save your project to make sure
that you didnt introduce any errors.
2013. All rights reserved.
CREATE A BASE ENUMERATION TO TRACK THE
APPROVAL STATUS
The state of any of the workflows will be tracked through an enumeration field, which allows you to assign any number of values to segregate out the different processes.
In this example we will show how to create a new Base Enumfield type to track the workflow statuses.
2013. All rights reserved.
Create a Base
Enumeration to
Track the Approval
Status
From within the workflow development project, right-
mouse-click on the parent folder, and from the New
menu, select Data Dictionary and then Base Enumto
create a new enumeration field for the statuses.
2013. All rights reserved.
Create a Base
Enumeration to
Track the Approval
Status
Change the Name of the enumeration to
ProductApprStatus and change the Label to be Product
Approval Status.
2013. All rights reserved.
Create a Base
Enumeration to
Track the Approval
Status
Now we need to define the valid values for the
enumeration. To create a new element, right-click on the
ProductApprStatus enumeration, and select the New
Element option.
2013. All rights reserved.
Create a Base
Enumeration to
Track the Approval
Status
This will create a new element for you that you can
change the Name to NotSubmitted and the Label to Not
Submitted.
2013. All rights reserved.
Create a Base
Enumeration to
Track the Approval
Status
Repeat to create elements for Submitted, Approved, and
Rejected.
2013. All rights reserved.
Create a Base
Enumeration to
Track the Approval
Status
After you have done that, save the project and make sure
that there are not any errors in your update.
2013. All rights reserved.
ADD THE APPROVAL STATUS FIELD TO THE
PRODUCT TABLE
Now that we have a Base Enumeration that defines all of the possible states for the approval of the products, we need to add it to the Product table so that we can track the status of the
records.
In this example we will show how to add a new field to the InventTable based off the approval status.
2013. All rights reserved.
Add the Approval
Status Field to the
Product Table
Open up the AOT workspace so that you have both the
Workflow Project and the AOT tree displayed.
Within the AOT tree, open up the Tables group within the
Data Dictionary and find the InventTable table.
2013. All rights reserved.
Add the Approval
Status Field to the
Product Table
Drag the InventTable table over to the
ProductManagementWorkflows project.
2013. All rights reserved.
Add the Approval
Status Field to the
Product Table
Then drag the ProductApprStatus base enumeration that
you just created up into the Fields group.
2013. All rights reserved.
Add the Approval
Status Field to the
Product Table
Select the new ProductApprStatus field within the Fields
group of the InventTable table, and update the Label
property to be Product Approval Status.
2013. All rights reserved.
Add the Approval
Status Field to the
Product Table
After you have done that, just save the project.
2013. All rights reserved.
ADDING THE APPROVAL STATUS TO THE
RELEASED PRODUCTS FORM
Now that we have the status field on the table that we are going to trigger the workflow from, we can add it to the Released Products form so that we will be able to see the statuses of all
of the product approvals. The easiest way to do this is by personalizing the form.
In this example we will show how you can easily add the Approval Status field to the Released Products form.
2013. All rights reserved.
Adding the
Approval Status to
the Released
Products Form
From the Product Information Management area page,
open up the Released Products form from within the
Common group.
2013. All rights reserved.
Adding the
Approval Status to
the Released
Products Form
Right-mouse-click on the field headings of the grid form,
and select the Personalize option.
2013. All rights reserved.
Adding the
Approval Status to
the Released
Products Form
Then the Personalization dialog is displayed, click on the
Add Fields button underneath the Layout pane.
2013. All rights reserved.
Adding the
Approval Status to
the Released
Products Form
This will show you a list of all the fields that are associated
with the form. Expand out the InventTable table group,
and you will be able to find the Product Approval Status
field that you just added. Select the field, click on the Add
button, and then close the form.
2013. All rights reserved.
Adding the
Approval Status to
the Released
Products Form
Now you should see the new field in the ListPageGrid
group, and you can close the Personalization dialog.
2013. All rights reserved.
Adding the
Approval Status to
the Released
Products Form
Now the Approval Status will show in the list page.
2013. All rights reserved.
ADD A CANSUBMITTOWORKFLOW METHOD
TO THE TABLE TO ENABLE WORKFLOWS
Tables need to be enabled for workflow processing before they can be used by the workflows themselves. This is done simply by adding a method to the table called
canSubmitToWorkflow.
In this example we will show how you can add the canSubmitToWorkflowmethod to the tables to enable workflow processing.
2013. All rights reserved.
Add a
canSubmitToWorkflow
Method to the Table
to Enable Workflows
From within the ProductManagementWorkflows project,
open up the InventTable table explorer, and then right-
mouse-click on the Methods group, and select New
Method.
2013. All rights reserved.
Add a
canSubmitToWorkflow
Method to the Table
to Enable Workflows
This will create a new generic method for you.
2013. All rights reserved.
Add a
canSubmitToWorkflow
Method to the Table
to Enable Workflows
boolean canSubmitToWorkflow(str _workflowType='')
{
inventTable InventTable;
;
if(!this.ProductApprStatus == ProductApprStatus::NotSubmitted)
return false;
return true;
}
Replace the default code with the following:
2013. All rights reserved.
Add a
canSubmitToWorkflow
Method to the Table
to Enable Workflows
Check the coding and the syntax by saving the method. If
there are any errors then you should be able to fix them
here.
2013. All rights reserved.
Add a
canSubmitToWorkflow
Method to the Table
to Enable Workflows
After you have updated the method, return to the project
explorer, and then save the project again just to make
sure that there are not any problems.
2013. All rights reserved.
CREATE A QUERY ON THE PRODUCTS TABLE
FOR THE WORKFLOWS TO REFERENCE
Before we move on to the next step and create the workflow template, there is one final step, and that is to create a query onto the base table, in this case InventTable, that we will be able
to mark as dynamics and then use within the Workflow Wizard.
In this example we will show how to create a simple query on the products table.
2013. All rights reserved.
Create a Query on
the Products Table
for the Workflows
to Reference
Open up the AOT workspace so that you have both the
Workflow Project and the AOT tree displayed.
Within the AOT tree, open up the Tables group within the
Data Dictionary and find the InventTable table.
2013. All rights reserved.
Create a Query on
the Products Table
for the Workflows
to Reference
Right-mouse-click on the root of the project tree and
select the Query option from the New sub-menu to
create a new Query element.
2013. All rights reserved.
Create a Query on
the Products Table
for the Workflows
to Reference
Change the Name property to ProductApprQuery.
2013. All rights reserved.
Create a Query on
the Products Table
for the Workflows
to Reference
Open up the ProductApprQuery within the project and
drag the InventTable table from the AOT explorer over
into the Data Sources.
2013. All rights reserved.
Create a Query on
the Products Table
for the Workflows
to Reference
Select the Fields from within the InventTable_1 Data
Source, and change the Dynamic property to Yes.
2013. All rights reserved.
Create a Query on
the Products Table
for the Workflows
to Reference
Now save your project to make sure that nothing broke
before continuing on.
2013. All rights reserved.
CREATE A WORKFLOW TYPE USING THE
WORKFLOW WIZARD
In the past, creating a workflow was made challenging because there was a lot of plumbing that was required in order to create the workflow type, and if you didnt have it all just right then
you spent forever trying to track down the problems. With the introduction of Dynamics AX 2012 though a wizard was added to the AOT tools that does almost all of the work for you so
that you dont have to be an experienced developer in order to create workflow templates.
In this example we will show how to use the Workflow Wizard to create almost all of the framework required for a workflow.
2013. All rights reserved.
Create a Workflow
Type Using the
Workflow Wizard
Open up the AOT explorer, and expand out the Workflow
node so that you can see the Workflow Types folder.
2013. All rights reserved.
Create a Workflow
Type Using the
Workflow Wizard
Right-mouse-click on the Workflow Types and select the
Workflow type wizard from the Add-Ins menu.
2013. All rights reserved.
Create a Workflow
Type Using the
Workflow Wizard
This will start the Workflow Wizard. Click on the Next
button to skip the welcome screen.
2013. All rights reserved.
Create a Workflow
Type Using the
Workflow Wizard
When the Create workflow type dialog page is shown,
type in ProductApproval into the Name field.
2013. All rights reserved.
Create a Workflow
Type Using the
Workflow Wizard
Select the workflow category that we set up in the earlier
stages (ProductManagementWFCategory) from the
Category dropdown.
2013. All rights reserved.
Create a Workflow
Type Using the
Workflow Wizard
Select the workflow category that we set up in the earlier
stages (ProductManagementWFCategory) from the
Category dropdown.
2013. All rights reserved.
Create a Workflow
Type Using the
Workflow Wizard
Select the workflow category that we set up in the earlier
stages (ProductManagementWFCategory) from the
Category dropdown.
2013. All rights reserved.
Create a Workflow
Type Using the
Workflow Wizard
Once you have selected the options for the Workflow
Wizard, click on the Next button to move to the next step.
2013. All rights reserved.
Create a Workflow
Type Using the
Workflow Wizard
When the confirmation box is displayed, just click on the
Finish button to create the workflow type.
2013. All rights reserved.
Create a Workflow
Type Using the
Workflow Wizard
If everything is OK, then you will be able to see a new
project has been created, and you will be warned that you
should run an incremental CIL generation. Click the OK
button to exit.
2013. All rights reserved.
Create a Workflow
Type Using the
Workflow Wizard
When you return to the new project, select the Generate
Incremental CIL option from the Build menu.
2013. All rights reserved.
Create a Workflow
Type Using the
Workflow Wizard
After a short amount of time, the build should complete
and you can continue on.
2013. All rights reserved.
CREATE A SIMPLE PRODUCT APPROVAL
WORKFLOW
Now that we have created our workflow, we can actually create a simple approval workflow through the workflow designer.
In this example we will show you how to create a new product approval workflow.
2013. All rights reserved.
Create a Simple
Product Approval
Workflow
From the Product information management area page,
select the Product information management workflows
menu item that we added in the previous steps.
2013. All rights reserved.
Create a Simple
Product Approval
Workflow
This will send you to the workflow list page, which will be
blank right now because there are no workflows defined
for the Product Management category.
2013. All rights reserved.
Create a Simple
Product Approval
Workflow
Click on the New button in the New group of the
Workflow ribbon bar. This will open up a Create
workflow dialog box that will list any workflow types that
you have associated with the form. Double click on the
workflow that you just created, to create a new design for
the workflow.
2013. All rights reserved.
Create a Simple
Product Approval
Workflow
When the workflow designer canvas is displayed, drag a
Manual decision action over from the Workflow
elements palette and put it under the Start element.
2013. All rights reserved.
Create a Simple
Product Approval
Workflow
Then drag the connectors to join up the three elements,
creating a decision path for the approval.
Tip: All of the missing details will be displayed in the
Errors and Warnings section. Rather than hunting them
down through the ribbon bar, just click on them one by
one and you will be taken to where configurations are
missing.
2013. All rights reserved.
Create a Simple
Product Approval
Workflow
First set the Assignment type to User.
2013. All rights reserved.
Create a Simple
Product Approval
Workflow
Switch to the User tab and assign a user to the task.
2013. All rights reserved.
Create a Simple
Product Approval
Workflow
Then in the Manual decision step assign a Name, Work
item subject and some Work item instructions.
2013. All rights reserved.
Create a Simple
Product Approval
Workflow
Also, in the Outcomes tab, set the Outcomes to Approved
and Rejected.
2013. All rights reserved.
Create a Simple
Product Approval
Workflow
Finally, add an explanation of the workflow in the
Submission instructions.
2013. All rights reserved.
Create a Simple
Product Approval
Workflow
When you return to the designer canvas, you should se no
more errors in the Errors and warnings pane, and you can
click the Save and close button to commit the changes.
2013. All rights reserved.
Create a Simple
Product Approval
Workflow
Give your version some notes to explain what it is used
for, and then click the OK button.
2013. All rights reserved.
Create a Simple
Product Approval
Workflow
To finish the process, activate the workflow by selecting
the Activate the new version radio button, and then click
the OK button.
2013. All rights reserved.
Create a Simple
Product Approval
Workflow
When you return to the workflow list, you will be able to
see your new Product Approval workflow.
2013. All rights reserved.
ENABLING WORKFLOW SUBMISSION ON THE
PRODUCT DETAILS FORM
In order for the workflow controls to show up on the forms, you need to enable them to be used by workflows, and also associate the default workflow type to the form. This stops
workflow management steps from showing up randomly on forms, and also allows you to control who is able to act upon workflows.
In this example we will show how to enable workflows on particular forms.
2013. All rights reserved.
Enabling Workflow
Submission on the
Product Details
Form
Open up the AOT workspace so that you have both the
ProductApprovalWFType Project and the AOT tree
displayed. Within the AOT tree, open up the Forms group
within the Data Dictionary and find the
EcoResProductDetailsExtended form.
2013. All rights reserved.
Enabling Workflow
Submission on the
Product Details
Form
Drag the EcoResProductDetailsExtended form from the
AOT browser over to the ProductApprovalWFType
project.
2013. All rights reserved.
Enabling Workflow
Submission on the
Product Details
Form
Expand out the EcoResProductDetailsExtended form
definition and open the Designs section. Select the
DesignList design to enable workflow on that view.
2013. All rights reserved.
Enabling Workflow
Submission on the
Product Details
Form
In the properties for the DesignList change the
WorkflowEnabled property to Yes.
2013. All rights reserved.
Enabling Workflow
Submission on the
Product Details
Form
Select the InventTable table from the
WorkflowDatasource dropdown box.
2013. All rights reserved.
Enabling Workflow
Submission on the
Product Details
Form
And then from the WorkflowType dropdown box, select
your workflow type that is associated with the
InventTable table.
2013. All rights reserved.
Enabling Workflow
Submission on the
Product Details
Form
You should be able to save the project now and not have
any errors.
2013. All rights reserved.
UPDATING THE SUBMISSION MANAGER
METHOD TO START THE WORKFLOW
By default, the submission method that is created by the Workflow Wizard is empty, so we need to ad a little bit of code to tell the system what to do when the user clicks on the Submit
button to initiate the workflows.
In this section we will show how to update the Submit method for the workflow to make it start the workflows running correctly.
2013. All rights reserved.
Updating the
Submission
Manager Method to
Start the Workflow
Open up the ProductApprovalWFType project, and from
the Classes group, double click on the
ProductApprovalSubmitManager class.
2013. All rights reserved.
Updating the
Submission
Manager Method to
Start the Workflow
This will open up the method browser, and you can select
the main method.
2013. All rights reserved.
Updating the
Submission
Manager Method to
Start the Workflow
static public void main(Args args)
{
recId recId = args.record().RecId;
WorkflowCorrelationId workflowCorrelationId;
WorkflowTypeName workflowTypeName = workFlowTypeStr(ProductApproval);
WorkflowComment note = "";
WorkflowSubmitDialog workflowSubmitDialog;
InventTable InventTable;
workflowSubmitDialog = WorkflowSubmitDialog::construct(args.caller().getActiveWorkflowConfiguration());
workflowSubmitDialog.run();
if (workflowSubmitDialog.parmisClosedOK())
{
recId = args.record().RecId;
InventTable = args.record();
note = workflowSubmitDialog.parmWorkflowComment();
try
{
ttsbegin;
workflowCorrelationId = Workflow::activateFromWorkflowType(workflowTypeName,recId,note,NoYes::No);
InventTable.ProductApprStatus = ProductApprStatus::Submitted;
info("Submitted to workflow");
ttsCommit;
}
catch (Exception::Error)
{
info("Error on workflow activation.");
}
}
args.caller().updateWorkflowControls();
}
Update the main method to look like this:
2013. All rights reserved.
Updating the
Submission
Manager Method to
Start the Workflow
After you have updated the method, save it, and if there
are any syntax errors, then you will be able to correct
them here in the editor. When everything is fine, you can
code out of the method editor.
2013. All rights reserved.
Updating the
Submission
Manager Method to
Start the Workflow
Just to be sure, save your project to make sure that there
arent any other grammatical errors in the code.
2013. All rights reserved.
RELABEL THE WORKFLOW SUBMISSION MENU
ITEMS
The default labels that are generated by the Workflow Wizard for the submission menu items are a little generic, so it is a good idea to just fix the labels so that they look more appealing to
the user.
In this example we will show how to relabel the submission buttons for the workflow so that they look better.
2013. All rights reserved.
Relabel the
Workflow
Submission Menu
Items
Open up the ProductApprovalWFType project and open
the Menu Items group so that you can see the Submit and
Cancel items.
2013. All rights reserved.
Relabel the
Workflow
Submission Menu
Items
Select the ProductApprovalCancelMenuItemand set the
Name to Cancel and the Help Text to Cancel workflow.
2013. All rights reserved.
Relabel the
Workflow
Submission Menu
Items
Select the ProductApprovalSubmitMenuItemand set the
Name to Submit and the Help Text to Submit workflow.
2013. All rights reserved.
Relabel the
Workflow
Submission Menu
Items
When you have finished, save the project to catch any
errors.
2013. All rights reserved.
UPDATE THE COMPLETED METHOD ON THE
APPROVAL EVENT HANDLER
The final update that we need to do on our workflow type is to add some code top the Approval Handler to tell the workflow what to do when the workflow completes.
En this example we will show hot to update the Approval Event Handler.
2013. All rights reserved.
Update the
Completed Method
on the Approval
Event Handler
Open up the ProductApprovalWFType project and open
the Classes group select the
ProductApprovalEventHandler class.
2013. All rights reserved.
Update the
Completed Method
on the Approval
Event Handler
This will open up the method browser, and you can select
the completed method.
2013. All rights reserved.
Update the
Completed Method
on the Approval
Event Handler
public void completed(WorkflowEventArgs _workflowEventArgs)
{
InventTable InventTable;
select forupdate InventTable where InventTable.RecId == _workflowEventArgs.parmWorkflowContext().parmRecId();
if (InventTable.RecId)
{
InventTable.ProductApprStatus = ProductApprStatus::Approved;
InventTable.write();
}
}
Update the completed method to look like this:
2013. All rights reserved.
Update the
Completed Method
on the Approval
Event Handler
After you have updated the method, save it, and if there
are any syntax errors, then you will be able to correct
them here in the editor. When everything is fine, you can
code out of the method editor.
2013. All rights reserved.
Update the
Completed Method
on the Approval
Event Handler
Just to be sure, save your project to make sure that there
arent any other grammatical errors in the code.
2013. All rights reserved.
USING THE TUTORIAL WORKFLOW
PROCESSOR TO PROCESS WORKFLOWS
Before we start workflows running, we need to make sure that workflow processor is up and running so that it is able to move workflows from stage to stage. If you are running in a
development environment, a simple way to do this is to use the tutorial_workflowprocessor which you can find hidden away in AOT. This allows you to start and stop the workflow
processor on demand.
In this example we will show how you can access and start the tutorial version of the Workflow Processor.
2013. All rights reserved.
Using the Tutorial
Workflow Processor
to Process
Workflows
Open up the AOT explorer and expand the Forms node.
Find the Tutorial_WorkflowProcessor form, right-mouse-
click on it and select the Open menu item.
2013. All rights reserved.
Using the Tutorial
Workflow Processor
to Process
Workflows
When the workflow processor dialog box is displayed,
click the Start button.
2013. All rights reserved.
Using the Tutorial
Workflow Processor
to Process
Workflows
Now as long as you have the processor running, it will
automatically process any workflow steps that are in the
queue.
2013. All rights reserved.
PERFORMING THE WORKFLOW APPROVAL
THROUGH THE DYNAMICS AX FORMS
Now that the workflow has been associated with the form, you can submit the product to the workflow process, and also performapproval steps.
In this example we will show how to submit and act upon the workflows through the Dynamics AX forms.
2013. All rights reserved.
Performing the
Workflow Approval
Through the
Dynamics AX Forms
The first thing that you will notice now that the workflow
has been associated with the form is that there will be a
workflow header at the top of the form. This allows you
to see the workflow that is associated with the form, and
also submit the record to the workflow.
2013. All rights reserved.
Performing the
Workflow Approval
Through the
Dynamics AX Forms
If you click on the icon just to the left of the Submit
button, Dynamics AX will show you the submission
instructions that you have defined for the workflow.
2013. All rights reserved.
Performing the
Workflow Approval
Through the
Dynamics AX Forms
To submit the product to the approval workflow process,
all you need to do is click on the Submit button.
This will open up a comment dialog box. If you want, you
can enter any comments into the Comment field, and
then click the Submit button.
2013. All rights reserved.
Performing the
Workflow Approval
Through the
Dynamics AX Forms
The Submit button will change now to reflect the options
for the current workflow step. In this case we will see the
Approved and Rejected options for out manual decision,
and also the standard Delegate and Cancel workflow
actions.
2013. All rights reserved.
Performing the
Workflow Approval
Through the
Dynamics AX Forms
If you click on the View History action, you will be able to
see the current status of the workflow, and also all of the
steps that have been performed up until this point on the
workflow.
2013. All rights reserved.
Performing the
Workflow Approval
Through the
Dynamics AX Forms
If you click on the Approved action, the workflow
processor will open up a comment dialog box. If you
want, you can enter any comments into the Comment
field, and then click the Approved button.
2013. All rights reserved.
Performing the
Workflow Approval
Through the
Dynamics AX Forms
Now that the approval process is complete, the Actions
button will only show the View history option.
2013. All rights reserved.
Performing the
Workflow Approval
Through the
Dynamics AX Forms
If you click on the View History action, you will be able to
see that the status of the workflow is completed and also
see when it was completed.
2013. All rights reserved.
SUMMARY
In this walkthrough we showed how you can create your own workflow templates and activities. The product approval process could easily be extended out to include more steps and
approvals for the products, allowing for it to be used for new product introduction and development.
This does not just have to apply to product approvals though, you can use exactly the same process to create workflow templates for the approval of other areas where the approval
processes may be needed such as Customer, Vendors and BOMS. All you need to do is change the base tables and forms that are being referenced and the process will be almost identical.
You can also extend out the approval logic to update more information through the workflows like flags for allowing the use of the record after it has been activated, and also incorporating
information that has been gathered during the process. If you want to get really creative, you can even create custom workflow elements that incorporate other technologies like Outlook
for the creation of tasks and appointments.
Dont be afraid to create new workflow templates, once you have built them, then they will provide a much better way to streamline your business processes, and the hour or so that you
spend creating them will be recouped quickly by the removal of the manual workarounds that would have been used without them.
2013. All rights reserved.
THEN CHECK OUT THE KINDLE EDITION FOR
EXTRA CONTENT
Searching for more detail?
I created the Kindle Edition of this blueprint to provide an easier way for you all to reference
all of the examples that are here , and also to make the images easier to view. As a bonus. I
have included some extra content in the Kindle edition that you cannot get through the blog
post or the presentation.
Configuring the Workflow Processors to Run Automatically
Creating a Class to Manually Run Workflow Processes
Creating a New Product Approval Workflow Task Element
Relabeling the Approval Action Menu Item Labels
Update the Workflow Approval Element Event Handlers
Add the Product Approval Element to the Workflow Template
Using the Product Approval Element in the Approval Workflow
Performing Product Approval Using the Custom Approval Element
AMAZON: http://www.amazon.com/Dynamics-AX-2012-Blueprints-Developing-
ebook/dp/B00GHXYCHQ/
BLOG: http://extendingdynamicsax.com/2013/11/06/developing-a-product-
approval-workflow-in-dynamics-ax-2012/
2013. All rights reserved.
THEN PICK UP A COPY OF MY BOOK AND
SUPPORT A STARVING AUTHOR
Want to learn more?
Dynamics AX is built on a number of foundation products from Microsoft that are used to
make it bigger, better, and stronger than the average business system. Taking advantage of
these products will make your life easier. Use these tools to maximize the efficiency of your
business management, taking advantage of a powerful and centralized tool set.
"Extending Microsoft Dynamics AX 2012 Cookbook" will show you how to use tools that you
already have to extend out Dynamics AX and discover potential new directions. You will be
surprised at what you can do on a shoestring budget. The book will allow you to streamline
your work processes, and use the system's powerful and centralized features to the
advantage of your organization.
This is a book for those of you that want to make the most out of Dynamics AX by using what
you already have, and without breaking the bank.
FACEBOOK: http://www.facebook.com/extendingdynamicsax
AMAZON: http://www.amazon.com/Extending-Microsoft-Dynamics-2012-Cookbook-
book/dp/B00ESX15RW/
PACKT: http://www.packtpub.com/extending-microsoft-dynamics-ax-2012-
cookbook/book
Murray Fife is a aMicrosoft Dynamics AX MVP, a Presenter, an Author, and Solution Architect at I.B.I.S. Inc with over 18 years of experience in
the software industry.
Like most people he has paid my dues as a developer, as an implementation consultant, and a trainer. Ihehas a hard to find blend of technical
and interpersonal skills and spend his days working with companies solving their problems with the Microsoft suite of products, specializing in
the Dynamics AX solutions.
Unable to completely kick the habit of being a developer, countless prototypes have started their life on his desktop, only to be turned into
standard products and offerings. The projects that are too visionary (a.k.a. too out there) usually live on through my personal blog sites waiting
for others discover them.
EMAIL: murray@murrayfife.me
PHONE: +1 (770) 324-3862
TWITTER: @murrayfife
LINKEDIN: http://www.linkedin.com/in/murrayfife
BLOG: http://www.extendingdynamicsax.com
http://www.dynamicsaxtipoftheday.com
http://www.atinkerersnotebook.com
SLIDESHARE: http://slideshare.net/murrayfife/presentations
FACEBOOK: http://www.facebook.com/extendingdynamicsax
Murray Fife
Microsoft MVP, Dynamics AX
2013. All rights reserved.
2013 MURRAY FIFE
ALL RIGHTS RESERVED
The information herein is for informational purposes only and represents the current view of Murray Fife as of the date of this presentation. Because Murray Fife must respond to changing market conditions, it
should not be interpreted to be a commitment on the part of Murray Fife, and Murray Fife cannot guarantee the accuracy of anyinformation provided after the date of this presentation.
MURRAY FIFE MAKES NO WARRANTIES, EXPRESS, IMPLIED OR STATUTORY, AS TO THE INFORMATION IN THIS PRESENTATION.

Вам также может понравиться