3)
Create
a Workflow Type
1. Open the AOT.
2. Expand the Workflow node.
3.Right-click on the Workflow Types node and select Add-ins
> Workflow type wizard.
4. Click Next.
5. Enter SalesCreditLimitAppr in the name.
6. Enter SalesCategory in the Category.
7. Enter SalesCreditLimitApproval in the query.
8. Enter SalesTable in the Document menu item.
9. Click Next.
10.Click Finish. A development project with a number of newly
created elements will be displayed.
Create a Workflow Type (Step by Step with screen shot)
Enable Workflow
on a Form
Add a WorkflowState Field
1. Open the AOT.
2. Expand Data Dictionary.
3. Right-click on Base Enums and select New Base Enum.
4. Rename the new enum to SalesCreditLimitApprovalStatus
5.Add four elements to the Enum called NotSubmitted, Submitted,
Approved, Rejected.
6. Expand Tables > SalesTable.
7. Right-click on Fields and select New > Enum.
8. Right-click on the newly created field and select Properties.
9. Change the Name property to CreditLimitApprovalStatus.
10.Change the EnumType property to SalesCreditLimitApprovalStatus.
11. Right-click on the SalesTable node and select Save.
Add
a WorkflowState Field(Step by Step with screen shot)
Enable Workflow on the Form
1. Open the AOT.
2. Expand Tables > SalesTable.
3. Create a new method and add the method in the following code.
boolean canSubmitToWorkflow(str
_workflowType = '')
{
amountMST creditBalance; custTable custTable;
;
if (!this.CreditLimitApprovalStatus = =
SalesCreditLimitApprovalStatus::NotSubmitted) return false;
custTable = this.custTable_InvoiceAccount(); if (!custTable.CreditMax)
return
false;
creditBalance = custTable.CreditMax - custTable.balanceMST();
if(this.amountRemainSalesFinancial()+this.amountRemainSalesPhysical() < creditBalance) return false;
return
true;
}
4. Save the changes made to the table.
5. Expand Forms > SalesTableListPage > Designs.
6. Right-click on the design node and select Properties.
7. Change the WorkflowEnabled property to Yes
8. Change the WorkflowDatasource property to SalesTable.
9. Change the WorkflowType property to SalesCreditLimitAppr
10. Save your changes to the form
Enable Workflow on the form(Step by Step with screen
shot)
Create a Submit to Workflow Class
1. Press Ctrl+Shift+P to open the development projects window.
2. Expand Private.
3. Double-click on SalesCreditLimitApprWFType development
project.
4.In the development project find the class SalesCreditLimitApprSubmitManager.
5.Create a new method called submit, and copy the following code
for this method.
void submit(Args args)
{
// Variable declaration.
recId recId =
args.record().RecId; WorkflowCorrelationId workflowCorrelationId; // Hardcoded
type name
WorkflowTypeName workflowTypeName =workflowtypestr(SalesCreditLimitAppr);
//
Initial note is the information that users enter when they
//
submit the document for workflow. WorkflowComment note ="";
WorkflowSubmitDialog workflowSubmitDialog; SalesTable SalesTable;
// Opens the submit to workflow dialog.
workflowSubmitDialog
=
WorkflowSubmitDialog::construct(args.caller().getActiveWorkflowConfiguration());
workflowSubmitDialog.run();
if (workflowSubmitDialog.parmIsClosedOK())
{
recId =
args.record().RecId; SalesTable = args.record();
//
Get comments from the submit to workflow dialog. ttscommit;
}
catch(exception::Error)
{
info("Error on workflow activation.");
}
}
args.caller().updateWorkFlowControls();
}
note =
workflowSubmitDialog.parmWorkflowComment(); try
{
ttsbegin;
workflowCorrelationId =
Workflow::activateFromWorkflowType(workflowTypeName,recId,note,NoYes::No);
SalesTable.CreditLimitApprovalStatus =
SalesCreditLimitApprovalStatus::Submitted;
// Send an Infolog
message.
info("Submitted to workflow.");
6. Modify the code for the main method as shown in the following
code.
7. Press F8 to save and compile the code.
8. Find the menu item SalesCreditLimitApprSubmitMenuItem.
9. Change the Label property to Submit.
10.Right-click on the SalesCreditLimitApprSubmitMenuItem
menuitem and select Save.
Create a submit to Workflow Class (Step by Step with
screen shot)
Create a Workflow Approval
1. Open the AOT.
2. Expand the Workflow node.
3. Right-click on Approvals and select Add-ins > Approval
wizard.
4. Click Next.
5. Enter SalesCLApproval in Name.
6. Enter SalesCreditLimitApprDocument in Workflow document.
7. Enter Overview in Document preview field group.
8. Enter SalesTableListPage in Document menu item.
9. Click Next.
10.Click Finish. A development project with a number of newly
created elements is displayed.
11.Drag SalesCLApproval approval to the Supported elements
node on the SalesCreditLimitAppr workflow type.
12. Save your changes to the SalesCreditLimitAppr workflow type
Creating a Workflow Approval (Step by Step with screen
shot)
Create Event Handlers
Write code for Event Handler
1. Press Ctrl+Shift+P to open
the development projects window.
2. Expand Private.
3. Double-click on SalesCreditLimitApprWFType
development project.
4. In the development project find
the class SalesCreditLimitApprEventHandler.
The following code needs tobe added to the completed method of
the
SalesCreditLimitApprEventHandler class.
public void completed(WorkflowEventArgs
_workflowEventArgs)
{
SalesTable SalesTable;
select forupdate
SalesTable where SalesTable.RecId == _workflowEventArgs.parmWorkflowContext().parmRecId();
if(SalesTable.RecId)
{
SalesTable.CreditLimitApprovalStatus
= SalesCreditLimitApprovalStatus::Approved; SalesTable.write();
}
}
Add Element Level Event Handlers
1. In the AOT locate the class SalesCLApprovalEventHandler.
This class was created by the Approval element wizard.
2. Add the following code in the returned method
public void
returned(WorkflowElementEventArgs _workflowElementEventArgs)
{
SalesTable
SalesTable; ttsbegin;
select forupdate
SalesTable where SalesTable.RecId ==
_workflowElementEventArgs.parmWorkflowContext().parmRecId()
;
SalesTable.CreditLimitApprovalStatus
= SalesCreditLimitApprovalStatus::Rejected; SalesTable.update();
ttscommit;
}
3. Save your changes to the class.
4. In the AOT, right-click on the AOT node and select Incremental
CIL generation from X++
Author a Workflow
1.The workflow
category we created in the first procedure needs to be added to the main menu.
Create a new display menu item called WorkflowConfigurationSales.
2. Set the label to Sales workflows.
3. Set the object to WorkflowTableListPage.
4. Set the EnumTypeParameter
to ModuleAxapta.
5. Set the EnumParameter
to SalesOrder.
6. Add the new menu
item to SalesAndMarketting > Setup menu.
7.In the property
sheet for the new node in the menu, set the property IsDisplayedInContentArea
to Yes.
8. Save your changes
to the menu.
9. Open the main menu and select Sales
and Marketting > Setup > Sales workflows.
10. Click New.
11. Select SalesCreditLimitApprType
and click Create workflow.
The workflow editor window opens.
12.
Drag SalesCLApprovalApproval approval from the Workflow
elements window to the Workflow window.
13. Drag the bottom node of the Start box
to the top node of the Approval box.
14. Drag the bottom
node of the Approval box to the top node of the End box.
15. Double click on the
Approval box.
16. Click Step 1
17. Click Assignment.
18. On the Assignment
type tab, select User
19. On the User
tab, double click on Sammy
20. Click on Basic Settings and then
enter a subject and instructions for the approval
21. Click on Close
22. Click on Save
and Close
23. Enter some notes
for the new workflow if you wish.
24. Select to Activate
the new version
25. Click OK.
Authoring a Workflow (Step by Step with screen shot)
Test the Workflow
1. In the application workspace, navigate to Accounts receivable
> Common > Customers > All customers.
2. Select a customer and click Edit.
3. In the Credit and collections fasttab, set a credit limit.
4. Close the Customers form.
5. Go to Sales and marketting > Common > Sales
orders > All sales orders.
6. Click New sales order. Enter the customer account modified that
you modified the credit limit for and click ok.
7. Enter items and quantities in the sales lines so that the balance of
the customer plus the total amount on the lines is greater than the credit
limit.
8. The workflow Submit button and dialog should appear.
9. Click the Submit button and enter a comment.
10. Wait for the batch job to process the workflow request. This should
take one to two minutes.
11. Select Actions > History. You will see that the
document is waiting for approval by the person you assigned to approve it.
12. Logon to windows as the Sammy using the Switch User option on the
Start menu.
13. Start the Microsoft Dynamics AX client.
14. Open the Sales order form.
15. Click the workflow Actions button and select Approve.
16. Wait one to two minutes for the workflow engine to process the
approval.
17. The workflow has now been approved.