Saturday, February 18, 2012

How to start a Documentum Workflow from DFC

Launching and running a Documentum Workdlow from DFC code is not such a trivial task.
Below is a DFC code sample of starting a Workflow and attaching a package to it:

public void startWorkflow(IDfSession session, String processName, String wfName, String supervisorName) throws DfException {
if (processName == null || processName.equals("")) {
DfLogger.error(this, "the process is empty", null, null);
throw new IllegalArgumentException("The process name not specified");
}

IDfProcess process = (IDfProcess) session.getObjectByQualification("dm_process where object_name = '" + processName + "'");
if (process == null) {
DfLogger.error(this, "process not found!", null, null);
throw new DfException("startWorkflow - No such process: " + processName);
}

IDfWorkflowBuilder workflowBuilder = session.newWorkflowBuilder(process.getObjectId());
workflowBuilder.getWorkflow().setObjectName(wfName);
workflowBuilder.getWorkflow().setSupervisorName(supervisorName);
if ((workflowBuilder.getStartStatus() != 0) || (!(workflowBuilder.isRunnable()))) {
DfLogger.warn(this, "startWorkflow - workflow '" + wfName + "' is not runnable or StartStauts=0!", null, null);
throw new DfException("cannot start Workflow!");
}
workflowBuilder.runWorkflow();

// Adding attachments:
IDfList attachIds = new DfList();
attachIds.appendId(new DfId("09024a8580235bc4"));

IDfList startActivities = workflowBuilder.getStartActivityIds();
int packageIndex = 0;
for (int i = 0; i < startActivities.getCount(); i++) {
IDfActivity activity = (IDfActivity) session.getObject(startActivities.getId(i));
workflowBuilder.addPackage(activity.getObjectName(), activity.getPortName(packageIndex),
activity.getPackageName(packageIndex), activity.getPackageType(packageIndex), null, false, attachIds);
}
}

No comments:

Post a Comment