Thursday, June 9, 2011

API steps for workflow

here are the API steps to create a workflow instance:

>create,c,dm_workflow

(from this point on, l is the workflow object id)

>set,c,l,object_name

>your_object_name

>set,c,l,process_id

>your_wf_template_id

>save,c,l

> (if you need to fill out the alias set info, you can do it now)

> execute,c,l

> addpackage,c,l,...... (fill in your parameters. Please refer to the server manual. You have to make one addpackage call for each start activity and package)

________________________________________________________________________________

To start a workflow using APIs, log into the docbase using iapi or iapi32 on NT. Type the following commands at the API> prompt:

retrieve,c,dm_process where object_name = ''
(workflow template id will be returned)

create,c,dm_workflow
(workflow id will be returned)

set,c,l,process_id
(at the SET prompt enter the id of the workflow template)

save,c,l
(OK should be returned)

execute,c,l
(OK should be returned)

addpackage,c,l,Activity,Input:0,Pack age0,dm_document,,,(dmi_package_item id returned)

The 'l' listed above is a lower case L. It's an alias that means to use the last object_id returned.

This can also be done from the Interactive Message Tester in the Desktop Client or from Documentum Administrator

Tuesday, June 30, 2009

Audit of Completed workflows

Once a WF is completed, Dctm removes its corresponding entries from dm_workflow, dmi_workitem and dmi_package.Only dmi_queue_item contains details for the workflow_id.On enabling audit on WF, you get only the corresponding workflow details from dm_audittrail.

Why no data showed when we choose completed workflows in workflow reporting?

When selecting "Completed Workflows" under Workflow, Reporting shows results under the tab but the results does not have any link to view the completed workflow.
Include "dm_all_workflow" event in the Audit Management, so the object id and rest of the details will be stored in the audittrial table after the workflow is completed.
From DA go to Audit Management node;
Click ok "Manage Auditing by events selected for all objects in the repository";
Add "dm_all_workflow" via the Add "Event Name";
(Note for creating/editing audittrial you need to have appropriate Extended Privilieges for Audit)

Select * from dmc_completed_workflow

Some audit related queries

select * from dm_audittrail where event_description='All Workflow Events'
select * from dm_audittrail where event_name='dm_addattachment'

select dmi_workitem.r_workflow_id, dmi_workitem.r_creation_date, dmi_workitem.r_performer_name, dm_workflow.object_name from dmi_workitem, dm_workflow where dmi_workitem.r_workflow_id = '4d00303980000501' order by r_creation_date

select * from dmi_package

select object_name,r_object_type from dm_sysobject(ALL) where any i_folder_id IN (select id_5 from dm_audittrail where event_source='workflow' and event_name= 'dm_addpackage' )

To see date wise workflow tasks of a user
select * from dmi_queue_item where router_id='4d00303980001100' order by date_sent desc

If you want the documents processed in the workflow(current/completed).
Presuming the audit trail is enabled for the workflow activities,try this query.

select object_name from dm_document( or your custom type) where r_object_id in
(
select distinct r_component_id
from dmi_package dp,dm_audittrail_sp da,dm_workflow dw
where
dp.r_workflow_id = da.workflow_id
and da.event_source = 'workflow'
and da.event_name = 'dm_startworkflow'
and dp.r_workflow_id = dw.r_object_id
)


What can I query on a workflow to find out what document is being routed in that ?

The r_object_id of the document in the workflow is the r_component_id attribute of the dmi_package object for that workflow. Below are some example queries.
select r_component_id from dmi_package where r_workflow_id = '4dxxxxxxxxxxxxxx'
This will return the r_object_id of the document that is being routed in the workflow.
select object_name from dm_document where r_object_id in (select r_component_id from dmi_package where r_workflow_id = '4dxxxxxxxxxxxxxx');
This will return the name of the document being routed in the currently running workflow.
select object_name from dm_document where r_object_id in (select r_component_id from dmi_package where r_workflow_id in (select router_id from dmi_queue_item where r_object_id = '1bxxxxxxxxxxxxxx'));
This will return the object_name of the document that is being referenced by a running workflow that has a dmi_queue_item associated with it. This is useful if you are trying to find the document name, but you only have information about the queue item in the Documentum Inbox.
The attributes of dmi_queue_item do not refer to the document directly (in this case the dmi_package) that is being routed, but refers to the associated dmi_workitem. You can find out the package information, but you will have to be creative in the query that you run (see above examples).

Monday, June 22, 2009

How do I troubleshoot workflows which contain automatic activity

To troubleshoot workflows which contain automatic activity that does not run follow the steps below:
1. Check if workflow agent is up and running.
Here is what you look in the docbase log file to see if workflow agent has started up fine.
Wed Mar 10 19:52:06 2004 122000 [DM_WORKFLOW_I_AGENT_START]info: "Workflow agent master (pid : 3512, session 010003e880000007) is started sucessfully."
Wed Mar 10 19:52:07 2004 122000 [DM_WORKFLOW_I_AGENT_START]info: "Workflow agent worker (pid : 2872, session 010003e88000000a) is started sucessfully."
Wed Mar 10 19:52:08 2004 122000 [DM_WORKFLOW_I_AGENT_START]info: "Workflow agent worker (pid : 2860, session 010003e88000000b) is started sucessfully."
Wed Mar 10 19:52:09 2004 122000 [DM_WORKFLOW_I_AGENT_START]info: "Workflow agent worker (pid : 2892, session 010003e88000000c) is started sucessfully."

When docbase starts up, it starts workflow agent master and worker threads and prints above message to server logfile
Workflow agent cannot be started manually. It starts up during docbase startup.

2. The default out of the box automatic workflow method that we ship with server is called dm_noop_auto_method.
When automatic activity does not run please create a simple workflow with first activity as dm_noop_auto_method and second activity as a manual task.
Please turn on trace launch for dm_noop_auto_method, and run the workflow.
Trace launch information in logged in the docbase log.

Set Trace Launch attribute to True on the custom method object and run the Workflow again. Any errors that are encountered with the method will be displayed in the Server log. Review the server log and the trace launch information, check the method verb. The method verb and trace launch attribute can be checked

3. Check for wrong

spellings and case sensitivity in the method verb.
Dump the dm_noop_auto_method and compare with one in-house.

4. Dump the method object, check the attributes, use_method_content, method verb. If the
use_method_content attribute is set to True, your method verb attribute should not include a ?-f? parameter, it?s not necessary.
Example : ./dmbasic eEntry_Point

5. If you have users that are not receiving tasks following an automatic activity, check the
workflow_disabled attribute on those specific users. Dump the user, using the Dump API.
Example: dump ,c,

6. Please dump the server config object
dump,c,serverconfig

Please look for following two parameters.
wf_agent_worker_threads : 3
wf_sleep_interval : 3

By default out of the box server comes with these two parameters set to 3.

How to check timeout?
You can check your method timeouts using the following query
select r_object_id,object_name,launch_async,timeout_min,timeout_default,timeout_max from dm_method
where the timeout values are min <= default <= max. These values are valid for synchronous methods.


Why do I recieve an error message stating that 'Activity instance failed' ?

You may find that some of the documents make the transition and repeated requests to force the transition of the other documents eventually succeeds.For each method, the server launches a process to run it. For workflow automatic activity methods, the process is always launched synchronously. That means, if the process does not finish within time_out, the server kills the process. The time_out value comes from exec_time_out attribute of dm_activity, and it must fall between timeout_min and timeout_max attributes of the dm_method. Therefore this value can exist between 30 seconds and 7 days.

To resolve the above issue increase the timeout for automatic activities in your workflow. By default when creating an automatic activity the timeout for is 60 seconds.

How to know the r_runtime_state of the failed activites?

select r_runtime_state from dm_workflow where r_object_id in (select router_id from dmi_queue_item where where message like 'Activity instance%failed%' and router_id!='0000000000000000')


select a.r_object_id,a.object_name,a.process_id,a.supervisor_name,a.r_runtime_state,b.task_number,b.task_state,b.task_name,b.message,b.sent_by,b.date_sent from dm_workflow a,dmi_queue_item b where a.r_object_id=b.router_id and a.r_object_id in (select router_id from dmi_queue_item where message like 'Activity instance%failed%' and router_id!='0000000000000000')

Wednesday, June 10, 2009

How to track Workflows?

You could turn on the dm_all_workflow Audit trail event. In this case all workflows events are recorded in the dm_audittrail records. Timestamps are recorded in milliseconds, only Documentum Administrator does not return that so you have to analyze the results with an SQL client (SQL Developer for example) directly in the database (looking at dm_audittrail_s table).

select * from dmi_registry (to see the events that are being audited)

audit,c,dm_all_workflow (to audit all workflow events


How can I make sure that my documents will be audited correctly when I register

Keep in mind that auditing is designed for registering events for documents that are either a subtype of dm_document or dm_sysobject .

1) For verification create a subtype of dm_document and register an event against this subtype.

2) Then create a document whose attribute has this subtype.

3) Next register the events you would like to monitor.

- Launch Documentum Administrator

- Select auditing

- Clicking on the selection, "Register Events for all objects of a type". It is important that when this step is done, that you navigate to the correct folder such as dm_document and highlight the dm_type which you are registering the event against.

Then launch Intranet Client and trigger an event such as check in or check out. You should now have generated an event and possibly an email if your email service has been properly configured.



An event may not be viewable on the Audit Detail page in Workflow Reporting unless you turn on auditing for workflow template.

To turn on the workflow template audit, check Template Audit Record Setting option on Properties dialog box which is from File > Template Properties in Web Workflow Manager.

In addition, to turn on the workflow template audit, the user must have 'Config Audit' privilege. If the user does not have this privilege then this option is not available for this user on the workflow template properties dialog box.

System Event: System-recognized actions performed on specific documents, folders, cabinets, or other objects. Content Server supports a large number of system-defined events, representing operations such as checkins, promotions, and demotions. Refer to the Audit section of the Content Server API Reference Manual for tables listing all System Events. Also, Appendix B (System Events) of the Content Server API Reference provides an exhaustive list of the System Events.



Application Event: Actions which are not inherently recognized by the Content Server. Applications decide which of these non-system actions need to support audit and add code to specifically handle those actions. For example, an application may choose to provide audit capability for an advanced search function, capturing useful data in the audit such as the user executing the search and the search parameters.



Event Target: The primary entity acted upon by an event. Examples of targets for System Events include specific instances of an object, types of an object, users, groups, policies, methods, workflows, activites, etc. Application Events have their targets defined by their application.



Audit Event: An Audit Event is either a System Event or an Application Event. The term Audit Event is introduced as a generalization for convenience.



Audit Method: An Audit Method is used to request an audit of a specific event. The arguments to the Audit Method specify the event to audit, the target of the event, and the names of the attributes whose values are to be audited. Audit methods can be used to request audits for System Events or Application Events. A user must have the extended privilege Config Audit in order to invoke an Audit Method.



Audit Trail: An Audit Trail is the history of instances of an Audit Event. Each instance of an Audit Event results in the creation of one Audit Trail entry which stores information about the event (such as the time of the event, which objects were involved, who performed the actions, and which values were affected).



Tamper-Evident Auditing: The Content Server provides the ability to "sign" each Audit Trail entry, which will cause a cryptographic hash to be computed for the contents of the entry. The hash itself is then encrypted using the Application Encryption Key (AEK) for the Content Server and stored back in the audit_signature attribute of the entry. At any point in the future, a client can validate the entry, which will recompute the hash and compare it to the hash stored in the attribute. Due to the way hashes work, if any information in the entry has been changed since the original hash was computed, then the new hash will not match the original, and the client knows that the entry has been tampered.

Audit Trail is docbase specific
dmc_completed_workflow - completed workflow object stores information from audit trail records about a completed workflow. The objects are created by the dm_WfReporting job and used by Webtop’s aggregrate workflow reporting tool.
To fully populate the attributes in these objects, you must be auditing all workflow events.
The object type is created by a script when Content Server is installed.
When you clone, the Audit info will not be cloned because it is specific to the docbase. Setup auditing and perform a WF, you should see the results

What is the difference between Register and Audit API?
Register API: Registers the current user to receive notification when the specified event occurs.

When you register for an event, the server puts a notification in your inbox when the
event occurs. With two exceptions (dm_fetch and dm_acquire), you receive notification
each time the event occurs in the same or different repository sessions. For dm_fetch
and dm_acquire, you receive only one notification in a repository session even if the
event occurs multiple times in the session.
If you register for an event on an object type, you receive a notification every time that
event occurs for an object of the type.
Registering for an event doesn't create audit trail entries when the event occurs. To create
audit trail entries for an event, you must use an Audit method to initiate auditing. You
can both register for an event and audit the event. (Using Audit requires Config_audit
privileges.)



Audit API: Initiates auditing of an event.

You must have Config_audit privileges to use this method.
Executing Audit creates a dmi_registry object that records the auditing request. The
values you include in the Audit arguments are recorded in the registry object. Thereafter,
if the event is a system event, Content Server creates an audit trail entry whenever
the event occurs. If the event is an application event, the application can examine the
registry to determine whether to create an audit trail entry for the event.


Both API create a dmi_registry entry but have different purposes.



To check what are events are registered for a user or audited run this DQL:

DQL > select r_object_id, user_name, registered_id, event, is_audittrail from dmi_registry



If the event is audited, is_auditrail should be set to 1 and when the event occurs an entry will be created in the dm_audittrail table.

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.

What happens if automatic activity fails, and what should I do to get out of it

Solution and Explanation:
If workflow is initiated, workflow instance is created and set to state running state. As the workflow progresses, the runtime activity information is updated in dm_workflow object and workitem objects corresponding to the runtime activity staus are created.
After workflow is successfully completed, the workflow object and workitem objects are removed from Docbase.

If a method fails for a automatic activity, then workflow stays active state, but runtime activity goes to terminated state and workitem goes to Apaused.
You can restart the failed activity, with restart API. Resume API does not work in this case, since workflow and activity were not halted. SN 14292 is helpful to call restart.


State information for workflow, runtime activity are kept in dm_workflow object, and that for woritem are kept in workitem object.

<< workflow >>

r_runtime_state : current state of the workflow.

0, meaing dormant
1, meaning running
2, meaning finished
3, meaning halted
4, meaning terminated

r_act_name (R) : activity identifier as defined in dm_process object

r_act_state (R) : activity's current status

0, meaing dormant
1, meaning active
2, meaning finished
3, meaning halted
4, meaning terminated

<< work item >>

r_runtime_state

0, meaning dormant
1, meaning acquired
2, meaning finished
3, meaning paused
4, meaning Dpaused (a work item in the dormant state is paused)
5, meaning Apaused (a work item in the acquired state is paused)
6, meaning Ppaused (a work item in the paused state is paused)
Values 4-6 occur when a workflow containing the work item is halted.

Why are my automatic activities failing when using my custom methods on ContentServer

When an automatic activity is started, it is placed on a queue for execution.

The server facility responsible for executing automatic jobs wakes up at regular intervals and executes the activities in the order in which they appear on the queue. By default, the facility handles all queued activities before going to sleep.

Occasionally, we may encounter a problem with a custom method used in a Workflow Template. We may notice that the custom code associated with the method object is not running. But in many cases, we don't know where to begin to determine where the problem is.

Below is a series of tests that can be run to determine if it's your custom method that is failing or if it's something else on your eContent Server.

1. If your custom method is failing, most likely you will see 'paused' tasks in the Inbox of the user or users following the automatic activity.

This is typically the result of a syntax error in the code of the method. Verify that the method can run outside of the Workflow Template using an Apply API. Or run the method from the Documentum Administrator and test the code.

2 Replace your custom method with the dm_noop_auto method in your Workflow Template and run the Workflow again. If this works, that will indicate there is a problem with your custom method.

3. Turn Trace Launch on the custom method object and run the Workflow again, any errors that are encountered with the method will be displayed in the Server log. Review the server log and the trace launch information, check the method verb used.

4. Consider moving the method content file into the Docbase versus say placing it in the \bin directory on the eContent Server1.

If you do this, make sure, you update your method verb; it will not be necessary to include the '-f' for the file. Only the '-e' Entry Point will be necessary.

5. Check the header of the custom method code. Every method used in a Workflow Template needs the following parameters:

Sample below:

Sub Entry_Point (ByVal stub1 As String, _ ' -docbase

ByVal docbase As String, _

ByVal stub2 As String, _ ' -user

ByVal username As String, _

ByVal stub3 As String, _ ' -packageID

ByVal workitemID As String, _

ByVal stub4 As String, _ ' -ticket

ByVal ticket As String, _

ByVal stub5 As String, _ ' -mode

ByVal mode As String)

It doesn't have to be called 'Entry Point' but it does need to contain parameters listed.

6. Verify that the following APIs are used in the method content code.

- Connect, Acquire, and Complete

If you're uncertain about the syntax of these APIs, refer to the Server Reference Manual.

If one of these APIs is missing in your method code, your custom method will not work.

If you're looking for a code sample, view the method content for the 'dm_noop_auto' method.

This method object contains all of the APIs needed. When using this method object, it connects, acquires and performs a complete.

7. Check your method verb, for misspellings and case sensitivity.

8. Check if the agent exec process is running on the eContent Server. This will determine if the Workflow agent is running as well.

Note: you will not a see a workflow agent process id or process on your server.

9. Check the return value of the automatic method. See example below.

If the custom method exited with zero, server treated it as successful completion.

Therefore, if anything fails within the custom method, the method should exit with non-zero value. Then server knows the completion of the automatic activity failed and server will do something about the automatic workitem accordingly.

e.g. The following is part of the sample script dm_noop_auto_method, if the acquire failed, this script did exit with 10.

status = dmAPIExec("acquire," & sess & "," & packageID)

If status = False Then

Print "The acquire did not succeed"

Print dmAPIGet("getmessage," & sess)

dmExit(10)

End If

10. Are you trying to run this custom method with multiple packages?

There is a known bug on this issue. When attempting to use WF_PromoteLifecycle it fails to promote the optional packages and only promotes the required package. BUG#42500.

11. Setup and configure java.ini file, if Content Server runs on Unix platform.

This is documented in the Server installation guide on how to configure this file correctly.

Documentum provides a sample file called 'java_def.ini'. This file can be copied and modified.

Java.ini file needs to be under $DM_HOME\bin.

12. Update the Java Runtime Environment (JRE).

If using Content Server 5.1, java needs to be at 1.3.1.04 or 1.4.

If using eContent Server 4.2, java needs to be at 1.2.2