Sei sulla pagina 1di 2

canSubmitToWorkflow is not working at all in D365FO extensions, but we can achieve this by

creating custom workflow with new table which we will use sort of extension and associate the table
with standard form extension.

Following are the steps to create custom work flow and associate with existing form.

Step-1 Create custom Enum or you can use existing.

Step-2 Create custom table and add two fields Main field id and Status field extend both fields with

appropriate Enum or EDTs. In our case Table name is XXXXXX

Step-3 Create relation on parent table and our newly created table on the basis of Main field id.

Step-4 Create a Custom Query and Add the newly created table.

Step-5 Create workflow Type with the necessary datas

Step-6 Create workflow Approval with the necessary datas.

Step-7 Drag the workflow approval in workflow type.

Step-8 Override the canSubmitToWorkflow on newly created table.

Step-9 Create method in the table to update status on workflow events/approval.

Step-10 Place proper labels on workflow types, approval and menu items.

Step-11 Build the model and perform the database sync.

Step-12 Now navigate to workflow form of your module and click on new to create new workflow.

Step-13 Configure workflow as per your requirement and activate.

Step-14 Create extension of the form on which you want to associate workflow.

Step-15 Add data source table and join with parent data source.

Step-16 Only two type of join supported. Inner and outer.. in my case i am using outer join because

am having previous records.

Step-17 Override the initialized method of the newly added table data-source and enable the

workflow.

[FormDataSourceEventHandler(formDataSourceStr(YYYCaseRequestTable, NewlyCreatedTable),
FormDataSourceEventType::Initialized)]
public static void XXXXXXChild_OnInitialized(FormDataSource sender,
FormDataSourceEventArgs e)
{
sender.formRun().design().workflowDatasource(formDataSourceStr(FormName,
NewlyCreatedDataSourceName));
sender.formRun().design().workflowEnabled(true);
sender.formRun().design().workflowType(workflowTypeStr(WorkflowType));
}

Step-18 Now override the parent table Method OnWritten and insert the record on our newly added

data-source as well. Whenever user create or update parent table.

[FormDataSourceEventHandler(formDataSourceStr(YYYCaseRequestTable,
YYYCaseRequestTable), FormDataSourceEventType::Written)]
public static void YYYCaseRequestTable_OnWritten(FormDataSource sender,
FormDataSourceEventArgs e)
{
YYYCaseRequestTable objCaseRequestTable = sender.cursor();
FormDataSource fds =
sender.formRun().dataSource(formDataSourceStr(YYYCaseRequestTable,
NewlyCreatedTable));

fds.object(fieldnum(NewlyCreatedTable,RequestId)).setValue(objAMCaseRequestTab
le.RequestId);
fds.object(fieldnum(NewlyCreatedTable,approvalStatus)).setValue(YYYCaseRequest
TableWorkflowStatus::NotSubmitted);
fds.write();
}

Step-19 – Buid the model and you can verify with the new record.

Potrebbero piacerti anche