This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Move a document from a worflow/state to another WorkFlow/State depending of a property value

Hi All, I have been trying to do this creating this code in the AfterCheckinChangesFinalize EventHandler, unfortunatelly does not matter the adjustments to the code I Receive an error message.

The Issue is that for some documents of the same class the user want to select the process and the Metadata card configuration, so adding a property I can let them select, change the metadatacard configuration based on this property in the filter and based on the same property using the event handler I want to change the workflow and the state.

the permanent error is:

-The Value "8 - 0" does not exist, or it is a conflict object-

The code as follow:

Option Explicit
'move a document from it's actual WF and move it to another WF depending of I_OLD_DOC_PROP lo mueve al antiguo flujo de trabajo

Const I_MC_OLD_WF		= 131	'Old Document Format WorkFlow
Const I_MC_CLASS		= 1015	'Affected Class
Const I_OLD_DOC_PROP		= 1233  'Is Old or New Document Property

Dim iStatus, iClass, iWFState, iTargetWFS

Dim oPropertyValues: Set oPropertyValues = CreateObject( "MFilesAPI.PropertyValues" )
Set oPropertyValues = Vault.ObjectPropertyOperations.GetProperties( ObjVer )
Dim oWorkflowState: Set oWorkflowState = CreateObject( "MFilesAPI.ObjectVersionWorkflowState" )

iStatus = oPropertyValues.SearchForProperty( I_OLD_DOC_PROP	).TypedValue.GetLookupID
iClass = oPropertyValues.SearchForProperty( MFBuiltInPropertyDefClass ).TypedValue.GetLookupID
iWFState = oPropertyValues.SearchForProperty( MFBuiltInPropertyDefState ).TypedValue.GetLookupID

Dim oObjVer: Set oObjVer = CreateObject( "MFilesAPI.ObjectVersion" )
Set oObjVer = Vault.ObjectOperations.GetLatestObjVer( ObjVer.ObjID, False, False )
If iClass = I_MC_CLASS	And iStatus = 1 Then 'If Old Format document

	Select Case iWFState 'move to the correct State in the new workflow depending on the actual state
	
	Case	102	:	iTargetWFS =	499
	Case	103	:	iTargetWFS =	500

	End Select

	'If not CheckedOut, CheckOut and apply changes, then CheckIn
'	If Not Vault.ObjectOperations.IsCheckedOut( oObjVer.ObjID ) Then
	
				'Checkout object and Change WF and State
				Dim oCheckedOut ': Set oCheckedOut = CreateObject( "MFilesAPI.ObjectVersion"  )
				Set oCheckedOut = Vault.ObjectOperations.CheckOut( ObjVer.ObjID )
'				Vault.ObjectOperations.CheckOut ObjVer

				oWorkflowState.Workflow.TypedValue.SetValue MFDatatypeLookup, I_MC_OLD_WF
				oWorkflowState.State.TypedValue.SetValue MFDatatypeLookup, iTargetWFS
	
				oWorkflowState.VersionComment.TypedValue.SetValue MFDatatypeMultiLineText, "Generado automáticamente por M-Files desde Documento antiguo"
		
				Vault.ObjectPropertyOperations.SetWorkflowState oCheckedOut.ObjVer, oWorkflowState
				
				'CheckIn
				Vault.ObjectOperations.CheckIn oCheckedOut.ObjVer
'		Else
'			Err.Raise MFScriptCancel, "El objeto se encuentra protegido"	
			
'	End If 'NOT IsCheckedOut
End If 'iClass and iStatus

Any idea?

Parents
  • I wonder why you want to use a script and an eventhandler for this? As long as you stay within the same workflow you can handle this task with a simple automatic transition where you set a condition with the required property and property value for this transition to go ahead.

  • OK. When debugging scripts in general you need to look closely at the error message. It will contain a line where it says which script and which line in that script the error is generated from. Usually it is in the last 5 - 10 lines, so start looking from the bottom up.

    Once you have identified the erroneous line you can start digging into the method used and inputs needed for that method, and what is expected as output. You may have to place a line prior to the error and insert a statement that shows values in the input to the next line, something like:

    Err.Raise MFScriptCancel, <your variable>

    Once you are confident that your input is correct and has all the values needed for the method specified (sometimes input is listed as optional in documentation but it can be required in scripting anyway), then have a closer look at the output. What is 8 - 0 in your case?

Reply
  • OK. When debugging scripts in general you need to look closely at the error message. It will contain a line where it says which script and which line in that script the error is generated from. Usually it is in the last 5 - 10 lines, so start looking from the bottom up.

    Once you have identified the erroneous line you can start digging into the method used and inputs needed for that method, and what is expected as output. You may have to place a line prior to the error and insert a statement that shows values in the input to the next line, something like:

    Err.Raise MFScriptCancel, <your variable>

    Once you are confident that your input is correct and has all the values needed for the method specified (sometimes input is listed as optional in documentation but it can be required in scripting anyway), then have a closer look at the output. What is 8 - 0 in your case?

Children
  • Correct my friends, this is exactly what I use to do, but couldn't indentify that, property 8, object 8 does not exist at all, so we are still in the same page, I was some hours trying to Identify what it is.

  • Could you at least let us know which line of your script is generating the error. That gives us a chance to offer a somewhat qualified guess....

  • Sure!

    These are the lines with error:

    Vault.ObjectPropertyOperations.SetWorkflowState oCheckedOut.ObjVer, oWorkflowState

    Vault.ObjectOperations.CheckIn oCheckedOut.ObjVer

    The onject being modified have the ID 11757, version 10

    Line numbers does not meet because the original code is longer because the Case Select and was reduced for this publication.

    Lines in the error details represent lines 42 and 45 in the published code in the original post:

    1.- Vault.ObjectPropertyOperations.SetWorkflowState oCheckedOut.ObjVer, oWorkflowState

    ----AfterCheckInChangesFinalize::RestoreOldMcToOldWF, 63, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)

    2.- Vault.ObjectOperations.CheckIn oCheckedOut.ObjVer

    ---AfterCheckInChangesFinalize::RestoreOldMcToOldWF, 66, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)

    ShellFrameWnd.cpp, 4318, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    MetadataViewerPaneContent.cpp, 691, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    MetadataViewerWnd.cpp, 708, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    MetadataViewerWnd.cpp, 1455, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    MetadataViewerThread.cpp, 896, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    MetadataViewerWnd.cpp, 708, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    MetadataEditor.cpp, 2967, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    MetadataModel.cpp, 4262, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    MetadataModel.cpp, 4699, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    ElectronicSignatureUIHelper.cpp, 235, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    MetadataModel.cpp, 12176, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    CoVaultMountingDocumentOperations.cpp, 3127, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    DocumentCache.cpp, 11161, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    DocumentCache.cpp, 11270, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    DocumentCache.cpp, 19413, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    RPCMethodCallWithRetry.h, 35, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    RPCMethodCallWithRetry.h, 35, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    RPCDocumentOperations.cpp, 10664, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    RPCDocumentOperations.cpp, 6722, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    MCallInLoop.h, 349, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 6181, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 5873, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 10174, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 11072, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 11297, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    VaultDBSessionEvents.cpp, 335, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    VaultDBSessionEvents.cpp, 1508, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    VaultScriptSessionTemplates.cpp, 269, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    VaultScriptSessionTemplates.cpp, 328, Script execution failed. ((AfterCheckInChangesFinalize::RestoreOldMcToOldWF: 11757-11)) (0x800408BB)
    VaultScriptSessionTemplates.cpp, 328, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    VaultScriptSessionTemplates.cpp, 500, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    CoActiveScriptSite.cpp, 903, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    CoActiveScriptSite.cpp, 745, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    AfterCheckInChangesFinalize::RestoreOldMcToOldWF, 66, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    CoVaultObjectOperations.cpp, 604, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    ServerVaultObjectOperationsHelper.cpp, 65, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    RPCObjectOperationsHelper.cpp, 283, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    CoRPCOverCOM.cpp, 2355, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    RPCDocumentOperations.cpp, 5256, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    MCallInLoop.h, 349, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    RPCDocumentOperationsHelper.cpp, 4175, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    RPCDocumentOperationsHelper.cpp, 4028, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    RPCDocumentOperationsHelper.cpp, 10174, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    RPCDocumentOperationsHelper.cpp, 11072, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    RPCDocumentOperationsHelper.cpp, 11297, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    VaultDBSessionEvents.cpp, 335, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    VaultDBSessionEvents.cpp, 1508, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    VaultScriptSessionTemplates.cpp, 269, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    VaultScriptSessionTemplates.cpp, 334, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    VaultScriptSessionTemplates.cpp, 500, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    CoActiveScriptSite.cpp, 903, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    CoActiveScriptSite.cpp, 745, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    AfterCheckInChangesFinalize::RestoreOldMcToOldWF, 63, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    CoVaultObjectPropertyOperations.cpp, 1305, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    CoVaultObjectPropertyOperations.cpp, 1402, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    ServerVaultObjectPropertyOperationsHelper.cpp, 547, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    RPCObjectOperationsHelper.cpp, 109, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    CoRPCOverCOM.cpp, 2607, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    RPCDocumentOperations.cpp, 6722, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    MCallInLoop.h, 349, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    RPCDocumentOperationsHelper.cpp, 6181, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    RPCDocumentOperationsHelper.cpp, 5845, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    RPCDocumentOperationsHelper.cpp, 36481, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    RPCDocumentOperationsHelper.cpp, 37954, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    CheckObjIDExistence.cpp, 125, The value "8-0" does not exist, or it is a conflict object. (0x800408E8)
    (M-Files 20.12.9735.8)

  • I'm trying to understand your code, but for me, it looks kind of unlogical to set this script on 'AfterCheckinChangesFinalize' event and then try to check out the affected object (again). That could be the problem.

    I would say, use the 'AfterCheckinChangesFinalize', where you have the ObjVer directly available and make changes without the need to check-out/check-in (that's handled for you in the transaction).