Tuesday, 23 July 2013

Creation of Workflow module and workflow example in ax 2012:

In Microsoft Dynamics AX, modules are enabled for workflow. However, in some cases, you will need to create a new module that contains workflow. In each module that contains workflow, a Workflows list menu item must be added to the Setup pane. The following procedures are described in this topic:
  • Creating a new module enumeration.
  • Creating a display menu item for the Workflows list.
  • Creating a menu for the new module.
  • How to display the new menu in the client.
To Add a Module to the ModuleAxapta Base Enum
1.      In the Application Object Tree (AOT), expand the Data Dictionary node, expand Base Enums, right-click ModuleAxapta, and then click New Element. A new enumeration displays under the ModuleAxapta node.
2.      Right-click the new enumeration, and then click Properties.
3.      In the Properties sheet, select the Label property, and then enter the label of the new module.
To Create a Display Menu Item for the Workflows List
1.      In the AOT, expand the Menu Items node.
2.      Right-click the Display node, and then click New Menu Item. A new menu item displays under the Display node.
3.      Right-click the new display menu item, and then click Properties.
4.      In the Properties sheet, set the following properties.
Property
Value
Name
Set to WorkflowConfigurations<xxx> where <xxx> is replaced by a reference to the name of the new module. For example, you could set this value to WorkflowConfigurationsRecruit for a new module named Recruiting.
Label
Set text or a label that represents the text for the workflows list in the client.
ObjectType
Set to Form.
Object
Set to WorkflowTableListPage.
EnumTypeParameter
Set to ModuleAxapta.
EnumParameter
Set to the enum created in the preceding procedure.
5.      In the AOT, right-click the new display menu item, and then click Save.
After the new module enum and display menu item are created, you can add them to the Menus node.
To Create a Menu for a New Module
1.      In the AOT, right-click the Menus node, and then click New Menu. A new menu displays under the Menus node.
2.      Right-click the new menu, and then click Properties.
3.      In the Properties sheet, set the following properties.
Property
Value
Name
Set to a label or name of the new module.
Label
Set to a label that represents the text to display for the new menu in the client.
4.      In the AOT, right-click the new menu, point to New, and then click New Submenu. A submenu node displays under menu node created in the previous step.
5.      Right-click the new submenu node, and then click Properties.
6.      In the Properties sheet, set the following properties.
Property
Value
Name
Set to Setup or another label that represents the text for the Setup pane in the client.
Label
Set to Setup or another label that represents the text for the Setup pane in the client.
NormalImage
Set to 3478. This will display a gears icon for the setup pane.
ImageLocation
Set to EmbeddedResource.
7.      In the AOT, right-click the Setup node created in the previous step, point to New, and then click New Menu item. A new menu item displays under the Setup node.
8.      Right-click the new menu item, and then click Properties.
9.      In the Properties sheet, set the MenuItemName property to the display menu item created in the previous procedure.
10.    In the AOT, right-click the new menu item, and then click Save.
After the menu for the new module is created, you must add a reference to the menu in the MainMenu node to display the menu in the client.
To Add a Menu to the Client
1.      In the AOT, expand the Menus node, right click MainMenus, point to New, and then click Menu reference. The Select: Menus window is displayed.
2.      In the Select: Menus window, select the new module menu that you created in the previous procedure, and drag the menu to the MainMenu node in the AOT.
3.      In the AOT, right-click the MainMenu node, and then click Save.


In which module ur working go thaty module and open module(procurement and sourcing)workflow open nd create new one then select our workflow type giving flow chart
Forms-totorial_workflow processor form –open and once excute
   Then workflow approval starting


Home- (workflow approved person)- work items
                                                                 - work items assigned to me
                                                                 - workflow history


Steps:
First create one enum type (approval state)
One table having
Enum field
Submitted by field
Submitted date field
And one edt field
Here in that table 5 methods mandatory
1.Find():
public static WFTable find(Name    Name, boolean _forupdate = false)
{
    WFTable WFTable;//        leaveRequests;
;
    WFTable.selectForUpdate(_forupdate);

    if(Name)
    {
        select WFTable
            where WFTable.Name == Name;
    }

    return WFTable;
}

2.findRecId():
static WFTable findRecId(RecId    _recId,
                           boolean  _forUpdate = false)
{
    WFTable WFTable;
    ;

    if (_recId)
    {
        WFTable.selectForUpdate(_forUpdate);

        select firstonly WFTable
            where WFTable.RecId == _recId;
    }
    return WFTable;
}


3.can submit():
public boolean canSubmit()
{
;
    if(this.WFEnabled == ApprovalState::NotSubmitted  && this.RecId)
        return true;
    else
        return false;
}

4.cansubmittedworkflow():
Display boolean CanSubmitToWorkFlow(str _workflowtype =  '')
{
 return this.canSubmit();
}

5.UpdateWorkflowState ():
public static void UpdateWorkflowState(RefRecId _recId, ApprovalState _state)
    {
        WFTable WFTable = WFTable::findRecId(_recId, true);
         //Vacations       vacations;
        ttsBegin;

        //if(WFTable.IsWorkflowToBeResubmitted)
           // nsgLeaveRequests.IsWorkflowToBeResubmitted = false;
        WFTable.WFEnabled = _state;

        /*nsgLeaveRequests.update();
       //Commented and added by Britto on 16/10/2012
       // if(nsgLeaveRequests.WorkflowState == WFDummiesWorkflowState::Approved && SystemSetup::find().AutomaticVacationTransfromEP)

       if(nsgLeaveRequests.WorkflowState == NSGLeaveReqWorkflowState::ApprovedII )
        {
         /*   Vacations::CreateFromEPLeaveRequest(nsgLeaveRequests.LeaveRequestId,
                                                nsgLeaveRequests.EmplId,
                                                nsgLeaveRequests.VacationType,
                                                nsgLeaveRequests.LeaveFrom,
                                                nsgLeaveRequests.LeaveTo,
                                                NASVacationInitiateType::FormRequest,
                                                nsgLeaveRequests.Destination);*/



            //nsgLeaveRequests.VacationTransId =Vacations::CreateFromEPLeaveReq(nsgLeaveRequests);

            nsgLeaveRequests.Comments += "\n" + "Final Approval" +"\n" + nsgLeaveRequests.mostRecentComment();

        }
          if(nsgLeaveRequests.WorkflowState == NSGLeaveReqWorkflowState::ApprovedII )
        {
                  nsgLeaveRequests.Comments += "\n" + "HR Dept Comments" +"\n" + nsgLeaveRequests.mostRecentComment();
        }
           if(nsgLeaveRequests.WorkflowState == NSGLeaveReqWorkflowState::Approved )
        {
              nsgLeaveRequests.Comments += "\n" + "Dept Head Comment" +"\n" + nsgLeaveRequests.mostRecentComment();
        }
        */
          WFTable.update();
        ttsCommit;
   }


Then next Create a qury and add data sorce as our table
And then create form and desighn the form
Here in design properties set this three property as mandatory
(Workflow enabled-yes
Workflow datsource-ourtable name
Workflow type- our workflow type             ::this properties are set in last)

And then go to AOT:
1.Create workflow category
2.workflow type-rc-addins –create workflow type through wizard
3.approval- rc-addins –create workflow Approval through wizard
5. Incremental CIL
6. drag the approval to our workflow type supported element
And then
Write code in classes:
WFApprEventHandler():

Classdeclaratio():
class WFApprEventHandler implements    WorkflowElementCanceledEventHandler,  WorkflowElemChangeRequestedEventHandler,
                                                        WorkflowElementCompletedEventHandler, WorkflowElementReturnedEventHandler,
                                                        WorkflowElementStartedEventHandler, WorkflowElementDeniedEventHandler,
                                                        WorkflowWorkItemsCreatedEventHandler
{
}

Canceled():
public void canceled(WorkflowElementEventArgs _workflowElementEventArgs)
{
     WFTable::UpdateWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(), ApprovalState::Cancelled);
}

changeRequested():
public void changeRequested(WorkflowElementEventArgs _workflowElementEventArgs)
{
    WFTable::UpdateWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(), ApprovalState::ChangeRequest);
}

Completed():
public void completed(WorkflowElementEventArgs _workflowElementEventArgs)
{
    WFTable::UpdateWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(), ApprovalState::WorkflowCompleted);
}




created ():
public void created(WorkflowWorkItemsEventArgs _workflowWorkItemsEventArgs)
{
    // TODO:  Write code to execute once work items are created.
}


denied ():
public void denied(WorkflowElementEventArgs _workflowElementEventArgs)
{
   WFTable::UpdateWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(), ApprovalState::Returned);
}



returned ():
public void returned(WorkflowElementEventArgs _workflowElementEventArgs)
{
    WFTable::UpdateWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(), ApprovalState::Returned);
}

Started():
public void started(WorkflowElementEventArgs _workflowElementEventArgs)
{
    WFTable::UpdateWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(), ApprovalState::NotSubmitted);
}


WFTypeEventHandler():

Classdeclaration():

class WFTypeEventHandler implements    WorkflowCanceledEventHandler,  WorkflowCompletedEventHandler,
                                                        WorkflowStartedEventHandler
{
}

Canceled():
public void canceled(WorkflowEventArgs _workflowEventArgs)
{
    WFTable::UpdateWorkflowState(_workflowEventArgs.parmWorkflowContext().parmRecId(), ApprovalState::Cancelled);
}


completed ():
public void completed(WorkflowEventArgs _workflowEventArgs)
{
    WFTable::UpdateWorkflowState(_workflowEventArgs.parmWorkflowContext().parmRecId(), ApprovalState::WorkflowCompleted);
}


started ():
public void started(WorkflowEventArgs _workflowEventArgs)
{
    WFTable::UpdateWorkflowState(_workflowEventArgs.parmWorkflowContext().parmRecId(), ApprovalState::NotSubmitted);
}





WFTypeSubmitManager():

Classdeclaration():
public class WFTypeSubmitManager
{
    Name                        Name;
    WFTable                     WFTable;
    WorkflowVersionTable        workflowConfigurationTable;
    WorkflowComment             workflowComment;
    boolean                     submit;
    WorkflowWorkItemTable       workflowWorkItemTable;
    UserId                      userId;
    MenuItemName                menuItemName;
    WorkflowTypeName            workflowTemplateName;
    EPWorkflowControlContext    workflowControlContext;
}

dialogOk():

public boolean dialogOk()
{
    WorkflowSubmitDialog workflowSubmitDialog;
    WorkflowWorkItemActionDialog workflowWorkItemActionDialog;

    boolean ok;
    ;
    if (menuItemName == menuitemactionstr(WFTypeSubmitMenuItem))
    {
        workflowSubmitDialog = WorkflowSubmitDialog::construct(this.parmWorkflowConfigurationTable());
        workflowSubmitDialog.run();
        this.parmWorkflowComment(workflowSubmitDialog.parmWorkflowComment());
        ok = workflowSubmitDialog.parmIsClosedOK();
    }
    else if (menuItemName == menuitemactionstr(WFApprResubmitMenuItem))
    {
        workflowWorkItemActionDialog = WorkflowWorkItemActionDialog::construct( workflowWorkItemTable,
        WorkflowWorkItemActionType::Resubmit,
        new MenuFunction(menuitemactionstr(WFApprResubmitMenuItem), MenuItemType::Action));
        workflowWorkItemActionDialog.run();
        this.parmWorkflowComment(workflowWorkItemActionDialog.parmWorkflowComment());
        ok = workflowWorkItemActionDialog.parmIsClosedOK();
        userId = workflowWorkItemActionDialog.parmTargetUser();
    }
    return ok;
}


Init():
public void init( Common _documentRecord,
                    MenuItemName _menuItemName,
                    WorkflowVersionTable _workflowConfigurationTable,
                    WorkflowWorkItemTable _workflowWorkItemTable,
                    EPWorkflowControlContext _workflowControlContext
                    )
{
    this.parmWFTable(_documentRecord);
    this.parmSubmit(_menuItemName == menuitemactionstr (WFTypeSubmitMenuItem));
    this.parmMenuItemName(_menuItemName);
    if (_workflowControlContext)
    {
        this.parmWorkflowControlContext(_workflowControlContext);
        this.parmWorkflowWorkItemtable (_workflowControlContext.getActiveWorkflowWorkItem());
        this.parmWorkflowComment(_workflowControlContext.getWorkflowComment());
        this.parmWorkflowTemplateName (_workflowControlContext.getActiveWorkflowConfiguration().WorkflowTable().TemplateName);
    }
    else
    {
        this.parmWorkflowConfigurationTable(_workflowConfigurationTable);
        this.parmWorkflowWorkItemtable(_workflowWorkItemTable);
        this.parmWorkflowTemplateName (this.parmWorkflowConfigurationTable().WorkflowTable().TemplateName);
    }


}

parmMenuItemName():
public MenuItemName parmMenuItemName(MenuItemName _menuItemName = menuItemName)
{
    ;
    menuItemName = _menuItemName;
    return menuItemName;
}


parmSubmit ():
public boolean parmSubmit(boolean _submit = submit)
{
;
submit = _submit;
return submit;
}

parmWFTable():
public WFTable parmWFTable(WFTable _WFTable = WFTable)
{
    ;
    WFTable = _WFTable;
    return WFTable;
}

parmWorkflowComment():
public WorkflowComment parmWorkflowComment(WorkflowComment _workflowComment = workflowComment)
{
;
workflowComment = _workflowComment;
return workflowComment;
}

parmWorkflowConfigurationTable():
public WorkflowVersionTable parmWorkflowConfigurationTable(WorkflowVersionTable _workflowConfigurationTable = workflowConfigurationTable)
{
;
workflowConfigurationTable = _workflowConfigurationTable;
return workflowConfigurationTable;
}

parmWorkflowControlContext():
public EPWorkflowControlContext parmWorkflowControlContext(EPWorkflowControlContext _workflowControlContext = workflowControlContext)
{
;
workflowControlContext = _workflowControlContext;
return workflowControlContext;
}

parmWorkflowTemplateName():
public WorkflowTypeName parmWorkflowTemplateName(WorkflowTypeName _workflowTemplateName = workflowTemplateName)
{
;
workflowTemplateName = _workflowTemplateName;
return workflowTemplateName;
}

parmWorkflowWorkItemtable():
public WorkflowWorkItemTable parmWorkflowWorkItemtable(WorkflowWorkItemTable _workflowWorkItemTable = workflowWorkItemTable)
{
;
workflowWorkItemTable = _workflowWorkItemTable;
return workflowWorkItemTable;
}

reSubmit():
private void reSubmit()
{
    Object WFTable_ds;
    NoYes                   reSubmittingFromWeb;

    // If we have a workflow control context, we are being resubmitted from EP
    reSubmittingFromWeb = this.parmWorkflowControlContext() == null ? NoYes::No : NoYes::Yes;
    ttsbegin;

    WorkflowWorkItemActionManager::dispatchWorkItemAction( workflowWorkItemTable, workflowComment, userId, WorkflowWorkItemActionType::Resubmit, menuItemName, false);
    WFTable_ds = WFTable.dataSource();
    WFTable = WFTable::findRecId(WFTable.RecId, true);

    WFTable.WFEnabled = ApprovalState::Submitted;
    WFTable.doUpdate();
    if (WFTable_ds)
    {
        WFTable_ds.write();
        WFTable_ds.refresh();
    }
    ttscommit;
}

submit():
private void submit()
{
    Object WFTable_ds;
    NoYes activatingFromWeb;
    ;
    // If we have a workflow control context, we are being activated from EP
    activatingFromWeb = this.parmWorkflowControlContext() == null ? NoYes::No : NoYes::Yes;

    ttsBegin;
    Workflow::activateFromWorkflowType( this.parmWorkflowTemplateName(),WFTable.RecId, this.parmWorkflowComment(),activatingFromWeb, curuserid());
    WFTable_ds = WFTable.dataSource();
    WFTable = WFTable::findRecId(WFTable.RecId, true);
    WFTable.SubBy = curuserid();
  //  WFTable.SubDate = utcDateTime2SystemDateTime(DateTimeUtil::utcNow());
    WFTable.WFEnabled = ApprovalState::Submitted;
    WFTable.doUpdate();
    if (WFTable_ds)
    {
        WFTable_ds.write();
        WFTable_ds.reread();
        WFTable_ds.refresh();
    }
    ttsCommit;
}

construct():
public static WFTypeSubmitManager construct()
{
    return new WFTypeSubmitManager();
}



Main():
public static void main(Args args)
{
    WFTypeSubmitManager WFTypeSubmitManager;
    //EmplContract EmplContract;
    WFTable           WFTable;
     // Variable declaration.
    recId recId;
    WorkflowCorrelationId workflowCorrelationId;
    Object                          callerDataSource;

    // Hardcoded workflow type name
    workflowTypeName workflowTypeName = workflowtypestr("WFType");

    // Initial note is the information that users enter when they
    // submit the document for workflow.
    WorkflowComment initialNote = "Enter any comments here.";
    WorkflowSubmitDialog workflowSubmitDialog;

    // The name of the table containing the records for workflow.
    FormDataSource   WFTable_ds;

    // Workflow Control Context
    EPWorkflowControlContext workflowControlContext;

    ;
    WFTable = args.record();
    WFTypeSubmitManager = WFTypeSubmitManager::construct();
    if (args.menuItemName() == menuitemactionstr(WFTypeSubmitMenuItem) ||
        args.menuItemName() == menuitemactionstr(WFApprResubmitMenuItem))
    {
        WFTypeSubmitManager.init(args.record(), args.menuItemName(), args.caller().getActiveWorkflowConfiguration(), args.caller().getActiveWorkflowWorkItem(), null);
    }
    else
    {
        WFTypeSubmitManager.init(args.record(), args.menuItemName(), null, null, args.caller());
    }

    if (WFTypeSubmitManager.dialogOk())
    {
            if (WFTypeSubmitManager.parmSubmit())
            {
                WFTypeSubmitManager.submit();
            }
            else
            {
                WFTypeSubmitManager.reSubmit();
            }

            if (args.menuItemName() == menuitemactionstr(WFTypeSubmitMenuItem) ||
                args.menuItemName() == menuitemactionstr(WFApprResubmitMenuItem))
                    args.caller().updateWorkflowControls();
    }



    if (!webSession())
    {
        callerDataSource = args.record().dataSource();
        if (callerDataSource)
        {
            callerDataSource.research(true);
        }

        args.caller().updateWorkflowControls();
    }

}


































No comments:

Post a Comment