I have a workflow (created in Process Builder 6.5 SP1) with around 10 activities.
It has 2 packages.
Package0 - Mandatory
Type: mydocument
Visible across entire process: checked
This is mandatory package: checked
Package1 - Optional
Type: myacctgrp
Visible across entire process: unchecked
This is mandatory package: unchecked.
The Package1 is being used at the 5th activity. So that means that I need to start the workflow with just Package0.
But this workflow fails to start with just Package0. If in the code, I also add Package1 (while starting workflow), then it starts correctly.
From webtop, I am able to start it with just Package0.
Can someone please let me know what is wrong with my code
public void triggerWkf(String formObjectId) {
IDfSession session = getDfSession();
String wkfTemplateName = "MY_MAIN_PROCESS";
try {
IDfProcess wkfTemplateProcess = (IDfProcess) session.getObjectByQualification("dm_process where object_name ='"+ wkfTemplateName + "'");
IDfWorkflowBuilder workflowBuilder = session.newWorkflowBuilder(wkfTemplateProcess.getObjectId());
IDfId workflowId = workflowBuilder.initWorkflow();
workflowId = workflowBuilder.runWorkflow();
IDfActivity firstActivity = null;
String inputPortName = null;
boolean addedObject = false;
boolean addedAcctGrp = false;
IDfList idList = null;
IDfList listActivities = workflowBuilder.getStartActivityIds();
IDfId activityId = (IDfId) listActivities.getId(0);
firstActivity = (IDfActivity) session.getObject(activityId);
int portCount = firstActivity.getPortCount();
for (int count = 0; count < portCount; count++) {
if (firstActivity.getPortType(count).equalsIgnoreCase("INPUT"))
inputPortName = firstActivity.getPortName(count);
}
int packageCount = firstActivity.getPackageCount();
for (int count = 0; count < packageCount; count++) {
if (firstActivity.getPackageType(count).equalsIgnoreCase("mydocument")) {
if (!addedObject) {
idList = new DfList(IDfList.DF_ID);
idList.appendId(new DfId(folderId));
workflowBuilder.addPackage(firstActivity.getObjectName(), inputPortName,
firstActivity.getPackageName(count), firstActivity.getPackageType(count), "This is note text", false, idList);
addedObject = true;
}
}
}
}catch(DfException de) {
de.printStackTrace();
}
}Only if I add the following, it starts working
else if (firstActivity.getPackageType(count).equalsIgnoreCase("myacctgrp")) {
if (!addedAcctGrp) {
idList = new DfList(IDfList.DF_ID);
idList.appendId(new DfId("090004d28000eaf7"));
workflowBuilder.addPackage(firstActivity.getObjectName(), inputPortName,
firstActivity.getPackageName(count), firstActivity.getPackageType(count), "This is Account grp text", false, idList);
addedAcctGrp = true;
}
}