1. create a new base enum(YajLeaveWorkflowStatus or use the existing base enum
i. Not Submitted
ii. Submitted
iii. Approved
Add 2 or more Fields.
i. LeaveId (String)
ii. LeaveWorkFlowStatus (Drag and Drop Above created BaseEnum (YajLeaveWorkflowStatus)
a. canSubmitToWorkflow
b. updateWorkflowStatus
public boolean canSubmitToWorkflow(str _workflowType = '')
boolean ret;
ret = super(_workflowType);
if (this.LeaveWorkflowStatus == YajLeaveWorkflowStatus::NotSubmitted)
{
ret = boolean::true;
}
else
{
ret = boolean::false;
}
return ret;
}
static void updateWorkflowStatus(RefRecId _recId, YajLeaveWorkflowStatus _status)
{
YajLeaveTable yajLeaveTable;
select forupdate yajLeaveTable
where yajLeaveTable.RecId == _recId;
ttsBegin;
yajLeaveTable.LeaveWorkflowStatus = _status;
yajLeaveTable.update();
ttsCommit;
}
3. Create a new Query (Ex: YajLeaveQuery) Add above table(YajLeaveTable) and datasource and its Table property Dynamics fields: Yes
4. Create a new WorkflowCategory(Ex: YajLeaveWorkflowCategory)
Set the following properties for the “Work flow category”Label – Give the label.Module – Select the module (in which module this workflow category belongs Ex: HumanResource).
5. Create a new Form (YajLeaveForm) and Add Datasource as Table(YajLeaveTable).
i. Form pattern: Simplelist
* Action Pane* Group with Quick filter control* Grid
6. Create a new Display menu Item for above Form (YajLeaveDisplayMenuItem)
Add the properties options as Below image
Object type : FormObject : YajLeaveFormEnum Type Parameter : YajLeaveWorkflowStatus (Base Enum created in Point no .1)Enum Parameter : Submitted
7. Create a new Workflow Type((YajLeaveWorkflowType)
Choose Category: (Point no. 4)Query : (Point no. 3)Menu item : (Point no. 6)
public class YajLeaveWorkflowTypeEventHandler implements WorkflowCanceledEventHandler,
WorkflowStartedEventHandler
{
public void started(WorkflowEventArgs _workflowEventArgs)
{
// TODO: Write code to execute once the workflow is started.
YajLeaveTable::updateWorkflowStatus(_workflowEventArgs.parmWorkflowContext().parmRecId(),YajLeaveWorkflowStatus::Submitted);
}
public void canceled(WorkflowEventArgs _workflowEventArgs)
{
// TODO: Write code to execute once the workflow is canceled.
YajLeaveTable::updateWorkflowStatus(_workflowEventArgs.parmWorkflowContext().parmRecId(),YajLeaveWorkflowStatus::Submitted);
}
public void completed(WorkflowEventArgs _workflowEventArgs)
{
// TODO: Write code to execute once the workflow is completed.
YajLeaveTable::updateWorkflowStatus(_workflowEventArgs.parmWorkflowContext().parmRecId(),YajLeaveWorkflowStatus::Submitted);
}
}
update following code to YajLeaveWorkflowTypeSubmitManager
{
public static void main(Args args)
{
// TODO: Write code to execute once a work item is submitted.
YajLeaveTable yajLeaveTable;
WorkflowComment note = "";
WorkflowSubmitDialog workflowSubmitDialog;
WorkflowCorrelationId workflowCorrelationId;
WorkflowTypeName workflowTypeName = workFlowTypeStr("YajLeaveWorkflowType");
//Opens the submit to workflow dialog.
workflowSubmitDialog = WorkflowSubmitDialog::construct(args.caller().getActiveWorkflowConfiguration());
workflowSubmitDialog.run();
if (workflowSubmitDialog.parmIsClosedOK())
{
YajLeaveTable = args.record();
// Get comments from the submit to workflow dialog.
note = workflowSubmitDialog.parmWorkflowComment();
try
{
ttsbegin;
workflowCorrelationId = Workflow::activateFromWorkflowType(workflowTypeName, YajLeaveTable.RecId, note, NoYes::No);
YajLeaveTable.LeaveWorkflowStatus = YajLeaveWorkflowStatus::Submitted;
YajLeaveTable.update();
ttscommit;
// Send an Infolog message.
info("Submitted to workflow.");
}
catch (Exception::Error)
{
error("Error on workflow activation.");
}
}
args.caller().updateWorkFlowControls();
}
}
Note: Build the project now.
8. Create workflow Approval (YajLeaveWorkflowApproval)
Choose Workflow Document: (Created during Workflowtype creation Point no. 7)Field Group (YajLeaveTable field group: (Point no. 2)Menu item : (Point no. 6)
update following code to YajLeaveWorkflowApprovalEventHandler
public final class YajLeaveWorkflowApprovalEventHandler implements WorkflowElementCanceledEventHandler,
WorkflowElementCompletedEventHandler,
WorkflowElementReturnedEventHandler,
WorkflowElementStartedEventHandler,
WorkflowElementDeniedEventHandler,
WorkflowWorkItemsCreatedEventHandler
{
public void started(WorkflowElementEventArgs _workflowElementEventArgs)
{
// TODO: Write code to execute once the workflow is started.
}
public void canceled(WorkflowElementEventArgs _workflowElementEventArgs)
{
// TODO: Write code to execute once the workflow is canceled.
YajLeaveTable::updateWorkflowStatus(_workflowElementEventArgs.parmWorkflowContext().parmRecId(), YajLeaveWorkflowStatus::Submitted);
}
public void completed(WorkflowElementEventArgs _workflowElementEventArgs)
{
// TODO: Write code to execute once the workflow is completed.
YajLeaveTable::updateWorkflowStatus(_workflowElementEventArgs.parmWorkflowContext().parmRecId(), YajLeaveWorkflowStatus::Submitted);
}
public void denied(WorkflowElementEventArgs _workflowElementEventArgs)
{
// TODO: Write code to execute once the workflow is denied.
YajLeaveTable::updateWorkflowStatus(_workflowElementEventArgs.parmWorkflowContext().parmRecId(), YajLeaveWorkflowStatus::Submitted);
}
public void changeRequested(WorkflowElementEventArgs _workflowElementEventArgs)
{
// TODO: Write code to execute once change is requested for the workflow.
}
public void returned(WorkflowElementEventArgs _workflowElementEventArgs)
{
// TODO: Write code to execute once the workflow is returned.
YajLeaveTable::updateWorkflowStatus(_workflowElementEventArgs.parmWorkflowContext().parmRecId(), YajLeaveWorkflowStatus::Submitted);
}
public void created(WorkflowWorkItemsEventArgs _workflowWorkItemsEventArgs)
{
// TODO: Write code to execute once work items are created.
}
}
9. Now Goto Workflow Type (YajLeaveWorkflowType)
Note: If HRM CreateExtension not enable Update PersonnelManagement to current Model)
----------------------------------------------------------------------------------------------------------------------------
in D365FO FrontEnd : choose Module : Human resource --> Human Resource Workflow
-------------------------------------------------------------
Now goto HumanResource(HRM) module --> Workers Group --> Click Menu Item (leave form we created to open form)
Create some records as with Leave status as Not submitted.
