Wednesday, June 10, 2009

How to attach a document in already installed workflow?

This isn't too hard actually. As long as whatever document you are attaching meets the package criteria, you shouldn't have a problem. By that I mean, make sure that if you are adding an object of type dm_document, the package isn't looking for dm_xyz_custom_type.



If you already have a running workflow, you'll need to know the associated package or packages.



Note: It's confusing, but the IDfWorkflow.addAttachment method is not what you're looking for. Documents are routed through packages (IDfPackage).



You didn't mention how you needed to add a document to a workflow; either manually or through a workflow activity. I'll try and cover the bases. First, the easiest way is to add a document to a running workflow is find whoever has a pending workitem, open that task through their Documentum inbox and click the 'Add attachment' button. Problem solved. Ah, but it's never that easy. If you needed to manually slip in a document into a package, you can use a little DQL to find the most recent package for your workflow (providing you have the workflow_id):



SELECT r_object_id from dmi_package where r_workflow_id = '4d_yaddayadda'



Then a quick little API insert command setting the r_component_id to the r_object_id of the document you wish to insert (along with the other attributes you need) will also do the trick. However, you asked for a DFC method! Ah, you're in luck. I'm going to assume that you want to do this in a workflow activity of some such. That's good because it's easy to do so if you already have the workitem object. Here's some quick psuedocode that shows how to get a workflow package and insert the document you need. (I'm still rusty from the holidays so my code is going to be horrible.)



IDfWorkitem wi = (IDfWorkitem)sess.getObject(tasks.getId("item_id"));
IDfActivity act = wi.getActivity();
for (int i = 0; i < act.getPackageCount(); i++) // If you have more than one package
{
IDfId packageId = act.getPackageId(i);
IDfPackage packageObj = wi.getPackage(packageId);
String packageName = packageObj.getPackageName();

if (packageName.equals "Package0")

packageObj.appendId(r_component_id, object_id value of document being added to package)

packageObj.appendId(r_component_chron_id, object_id value of document being added to package)

packageObj.appendString(r_component_name, name of document being added to package)

packageObj.appendString(r_package_label, CURRENT)

}



That'll should do the trick. You don't want to use wi.addPackage because that would add an additional package to the workflow and you don't really want that if you can avoid it. That can cause all sorts of issues later on in the workflow. Hope this helps.

1 comment:

Kani Mozhi said...

This can be one particular of the most useful blogs We’ve ever arrive across on this subject. Basically Wonderful. I am also a specialist in this topic so I can understand your hard work.
Document Management Software
Document Management System
Electronic Document Management Software
Best Document Management Software