EMC Developer Network

 

Return to Index

How to Add a Workflow History to a Completed Package

There is no built-in functionality for automatically recording workflow history, this tip illustrates one way to do it.

On completion of the workflow the name of the last action owner of each activity is added to attributes of the documents in the workflow package.

Submitted by Documentum Technical Support. - July 2001

In this example, the document attached to the workflow has attributes that can hold information about who created, designed, draft-checked and engineering-checked the document.

To use this example,

  1. You will need create one workflow with at least 4 activities
    • "Approval"
    • "Design"
    • "Draft Check"
    • "Eng Check"
  2. Create a new object type and add the following string attributes
    • "approved"
    • "created_by"
    • "checked"
    • "engineered"
  3. Create a text file containing the method code. (Jump to code)
  4. Create a method which runs this code. (Jump to code)
  5. At end of the workflow add one activity item, set it as an automatic running activity run by dm_docbse owner and add the method object described in this example.

Note: THIS EXAMPLE IS ONLY FOR DEMONSTRATIONAL PURPOSES ONLY. Please do not call the technical support center regarding this code.



Step Three: Create the method code
' ****************** 
' main code for workflow history. 
' Create a text file and save it to c:\WF_History.txt. 
'============= NOTE ============== 
' THE FOLLOWING CODE EXAMPLE IS FOR TESTING PURPOSES ONLY ! 
'================================= 
' ****************** 

Sub WF_History (ByVal stub1 As String, _ 
	ByVal docbase As String, _ 
	ByVal stub2 As String, _ 
	ByVal user As String, _ 
	ByVal stub3 As String, _ 
	ByVal workItemId As String, _ 
	ByVal stub4 As String, _ 
	ByVal ticket As String, _ 
	ByVal stub5 As String, _ 
	ByVal mode As String) 

	On Error GoTo WF_History_Error 

	Dim clientX As Object 'dfclib.DfClientX 
	Dim client As Object 'IDfClient 
	Dim PersObject as Object 'IDfPersistentObject 
	Dim doc As Object 
	Dim docIdObj As Object 
	Dim docIdStr As String 
	Dim errorMsg as String 
	Dim packageCollection As Object 
	Dim session As Object 'IDfSession 
	Dim workItem As Object 
	Dim workItemIdObj As Object 

	Dim objID as String 'object as string 
	Dim SessID as String 'session id as string 
	Dim ObjName as String 'object name 
	Dim err_msg as String 
	Dim query as string 
	Dim workitem_id as string 
	Dim workflow_id as string 
	Dim process_id as string 
	Dim wf_activity_id as string 
	Dim index as integer 
	Dim activity_group (4,3) as string 


	'_____________________________________________ 
	' 
	' WF History Variable setting 
	' This array holds the 4 phases of the workflow that we are going to 
	' hold hostory data for. It holds the names of the attributes where the 
	' user names will be written to, it also stores the user names to be written.
	' 
	'_____________________________________________ 
	activity_group(0,0) = "Approval" 
	activity_group(1,0) = "Design" 
	activity_group(2,0) = "Draft Check" 
	activity_group(3,0) = "Eng Check" 

	activity_group(0,1) = "approved" 
	activity_group(1,1) = "created_by" 
	activity_group(2,1) = "checked" 
	activity_group(3,1) = "engineered" 

	workitem_id = workItemId 

	'_____________________________________________ 
	' 
	' Connection 
	'_____________________________________________ 
	' Get a session. 
	errorMsg = "Connecting to docbase" 
	sessionId = dmAPIGet("connect," & docbase & "," & user & "," & ticket) 
	If Basic.OS = ebWin32 Then 
		Set clientX = CreateObject("Documentum.Dfc") 
	Else 
		Set clientX = CreateObject("java:com.documentum.com.DfClientX") 
	End If 
	Set client = clientX.getLocalClient() 
	Set session = client.adoptDMCLSession(sessionId) 

	'_____________________________________________ 
	' 
	' Gets the process_id from the current 
	' workflow by using the workitem's ID supplied to the method.
	'_____________________________________________ 
	' 
	' get dm_process id from the active workitem
	Set PersObject = session.newObject("dmi_workitem") 
	' this method returns a IDfPersistentObject of type dm_document) 
	query="dmi_workitem where r_object_id = '" & workitem_id & "'" 
	set PersObject = session.getObjectByQualification(query) 
	workflow_id = PersObject.getString("r_workflow_id") 

	query="dm_workflow where r_object_id = '" & workflow_id & "'" 

	set PersObject = session.getObjectByQualification(query) 
	process_id = PersObject.getString("process_id") 


	'_____________________________________________ 
	' 
	' Get the user names of the users who last owned each activity in the workflow.
	'
	' Itterate through the workflow phases defined in the activity_group 
	' array and get the full name of the LAST PERSON WHO OWNED THAT ACTIVITY. This 
	' user name is written into element i,2 of the activity_group array.
	'
	' HOW DOES IT DO THAT?
	' It looks in the repeating attribute r_act_name on the dm_process object for the 
	' value that matches the required activity. Using this repeating atribute index 
	' it can look in the matched pair attribute r_act_def_id for the object ID of the
	' related workitem
	' It then looks up the performer name from the workitem and gets the fullname 
	' from the dm_user record. Neat.
	'_____________________________________________ 
	' 
	for i = 0 to ubound (activity_group) -1 
		query="dm_process where r_object_id = '" & process_id & "'" 
		set PersObject = session.getObjectByQualification(query) 
		index = PersObject.findString("r_act_name", activity_group(i,0)) 
		wf_activity_id = PersObject.getRepeatingString("r_act_def_id",index) 

		'get workitem id 
		query = "dmi_workitem where r_act_def_id = '" & wf_activity_id & _
				"' order by r_creation_date DESC" 
		set PersObject = session.getObjectByQualification(query) 
		
		' Get the short user name from this workitem
		activity_group(i,2) = PersObject.getString("r_performer_name") 

		' get the full user name 
		query = "dm_user where user_name = '" & activity_group(i,2) & "'" 
		set PersObject = session.getObjectByQualification(query) 
		activity_group(i,2) = PersObject.getString("description") 

		set PersObject = nothing 
	next i 

	'_____________________________________________ 
	' 
	' Acquire workitem 
	'_____________________________________________ 
	' 
	' Get work item id object. 
	errorMsg = "Getting work item id object" 
	Set workItemIdObj = clientX.getId(workItemId) 

	' Get work item object. 
	errorMsg = "Getting work item object" 
	Set workItem = session.GetObject(workItemIdObj) 

	' Acquire the work item only when mode = "0" for not restarting. 
	If mode = "0" Then 
		errorMsg = "Acquiring work item" 
		workItem.acquire 
	End If 

	'_____________________________________________ 
	' 
	' Package Handling 
	' We are going to write the attribute info back to the Documents inside the 
	' package, so we need to get this out of the package.
	'_____________________________________________ 
	' 
	' Get the packaged document 
	errorMsg = "Getting packages from work item" 
	Set packageCollection = workItem.getPackages("") 

	While packageCollection.Next 
		objID = packageCollection.getString("r_component_id") 
		Set docIdObj = clientX.getId(objID) 
		Set doc = session.GetObject(docIdObj) 

		' Set object attributes for each document in this package. 
		errorMsg = "Set values " + objID 

		for i = 0 to ubound (activity_group) -1 
			ret= doc.setString (activity_group(i,1), activity_group(i,2)) 
		next i 

		doc.save 
	Wend 
	packageCollection.Close 



	'_____________________________________________ 
	' 
	' Completion of workitem 
	'_____________________________________________ 

	' Complete the workitem. Assume there is 
	' only one output port for this task. 

	errorMsg = "Completing work item" 
	workItem.complete 

	set PersObject = nothing 
	set doc = nothing 
	set docIdObj = nothing 
	set clientX = nothing 
	set client = nothing 
	set session = nothing 
	set workItem = nothing 
	set workItemIdObj = nothing 
	set packageCollection = nothing 

	Exit Sub 

	WF_History_Error: 

	Print errorMsg 
	dmExit (100) 

End Sub 
 

Step Four: Create a new Method
'=================== 
' dm_method creation script file. 
'=================== 

create,c,dm_method 
set,c,l,object_name 
wf_history_with_Initial 
set,c,l,method_verb 
dmbasic -eWF_History 
set,c,l,run_as_server 
T 
set,c,l,use_method_content 
T 
set,c,l,a_special_app 
Workflow 
set,c,l,timeout_min 
30 
set,c,l,timeout_max 
300 
set,c,l,timeout_default 
60 
set,c,l,method_type 
dmbasic 
setfile,c,l,c:\WF_History.txt,crtext 
save,c,l 
getmessage,c 

Back to Top