Friday, 11 October 2013

Trigger Workflow Programmatically

// Get workflow process Name

IDfId processId = (IDfId) docObj.getSession().getIdByQualification("dm_process where object_name = '" + wfName + "'");

// Create workflowbuilder object and run the workflow

IDfWorkflowBuilder wfBuildObj = docObj.getSession().newWorkflowBuilder(processId);
                wfBuildObj.initWorkflow();
                wfBuildObj.runWorkflow();

// Add package to the workflow.

IDfList attachmentIds = new DfList();
            attachmentIds.appendId(docObj.getObjectId());

            IDfList startActIds = wfBuildObj.getStartActivityIds();
            IDfList startActName = wfBuildObj.getStartActivityNames();

            for (int i = 0; i < startActIds.getCount(); i++) {
                IDfActivity act = (IDfActivity) docObj.getSession().getObject((IDfId) startActIds.getId(i));

                int pkgCount = act.getPackageCount();
                for (int k = 0; k < pkgCount; k++) {
                    if (act.getPortType(k).equals("INPUT")) {
                        String activityName = (String) startActName.get(i);
                        String portName = act.getPortName(k);
                        String packageName = act.getPackageName(k);
                        String packageType = act.getPackageType(k);

                        if (docObj.getTypeName().equals(packageType) || docObj.getType().isSubTypeOf(packageType)) {
                                wfBuildObj.addPackage(activityName, portName, packageName, packageType, "", false,
                                    attachmentIds);
                        } else {
                                wfBuildObj.addPackage(activityName, portName, packageName, packageType, "", false, null);
                        }
                    }
                }

            }

No comments:

Post a Comment