Create Object Copy and send it to different Workflow State

Hi,

I’m trying to use Script "Copy Object" provided by Craig Hawker on github.

What I’m trying to get is to set different workflow state for newly cleated object.

But I’m getting error The value "-1" does not exist, or it is a conflict object.

I’d be grateful for any advice.

CODE

Option Explicit

' To create a copy of an object we need two things:
' 1. The PropertyValues for the new object (https://www.m-files.com/api/documentation/latest/index.html#MFilesAPI~PropertyValues.html)
' 2. The files for the new object (https://www.m-files.com/api/documentation/latest/index.html#MFilesAPI~SourceObjectFiles.html)

' Once we have these, we can call one of the CreateNewObject methods (e.g. https://www.m-files.com/api/documentation/latest/index.html#MFilesAPI~VaultObjectOperations~CreateNewObjectExQuick.html).

' Special folder value for TemporaryFolder, from https://msdn.microsoft.com/en-us/library/a72y2t1c(v=vs.84).aspx.
Const TemporaryFolder = 2
Const WORKFLOW = "WF.CopyObject" 
Const WORKFLOW_STATE = "WFS.CopyObject.PublishedCopy" 
	
' Create a filesystemobject to help working with files.
Dim objFSO: Set objFSO = CreateObject("Scripting.FileSystemObject")

' Let's get a copy of the property values.
Dim objNewObjectPropertyValues: Set objNewObjectPropertyValues = GetNewObjectPropertyValues(PropertyValues)

' Let's get a copy of the files.
Dim objNewObjectSourceFiles: Set objNewObjectSourceFiles = GetNewObjectSourceFiles(ObjVer)

' Is it a single-file-document (has exactly one file, and type of document)?
Dim bolIsSingleFileDocument: bolIsSingleFileDocument = False
If objNewObjectSourceFiles.Count = 1 AND ObjVer.Type = MFBuiltInObjectTypeDocument Then
	bolIsSingleFileDocument = True
End If

' Create the object.
Vault.ObjectOperations.CreateNewObjectExQuick ObjVer.Type, objNewObjectPropertyValues, objNewObjectSourceFiles, bolIsSingleFileDocument, True, CreateObject("MFilesAPI.AccessControlList")

' Clean up.
ClearTemporaryFiles objNewObjectSourceFiles

''' HELPER FUNCTIONS

' Gets a copy of the property values, for use when creating a new object.
Function GetNewObjectPropertyValues(oPropertyValuesToCloneFrom)
' Lookup the alieBes to IDs. 
Dim iWorkflow 
iWorkflow = Vault.WorkflowOperations.GetWorkflowIDByAlias(WORKFLOW) 
Dim iWorkflowState
iWorkflowState = Vault.WorkflowOperations.GetWorkflowStateIDByAlias(WORKFLOW_STATE)

'Get the workflow property value (hard-coded as always 38. 
' We should alias than !property in case of future release changes 
 
Dim oWorkflowPropertyDef : Set oWorkflowPropertyDef = PropertyValues.SearchForProperty(38) 
'Get the workflow property value (hard-coded as always 38. 
' We should alias than !property in case of future release changes 

Dim oWorkflowStatePropertyDef : Set oWorkflowStatePropertyDef = PropertyValues.SearchForProperty(39)
' Set the property values.

oWorkflowPropertyDef.TypedValue.SetValue MFDataTypeLookup, iWorkflow 
oWorkflowStatePropertyDef.TypedValue.SetValue MFDataTypeLookup, iWorkflowState
 
'Since we are changing multiple values, create a collection of property values. 
' We met each property value, add to the collection, and save the changes. 
Dim objNewObjectPropertyValues : Set objNewObjectPropertyValues = CreateObject("MFilesAPI.PropertyValues") 
objNewObjectPropertyValues.Add 0, oWorkflowPropertyDef 
objNewObjectPropertyValues.Add 0, oWorkflowStatePropertyDef 
' Save the changes. 
Set GetNewObjectPropertyValues = objNewObjectPropertyValues
	
End Function


' Downloads the files for the provided object version and creates a
' SourceObjectFiles collection for use when creating a new object.
Function GetNewObjectSourceFiles(oSourceObjVer)

	' Get a reference to the temporary folder.
	Dim strTempFolderPath: strTempFolderPath = objFSO.GetSpecialFolder(TemporaryFolder).Path

	' Get the files for the current objver.
	Dim objFiles: Set objFiles = Vault.ObjectFileOperations.GetFiles(oSourceObjVer)

	' Create our collection to return.
	Dim objSourceFiles: Set objSourceFiles = CreateObject("MFilesAPI.SourceObjectFiles")

	' Iterate over the files and download each in turn.
	Dim intCounter, objFile
	For intCounter = 1 To objFiles.Count
		
		' Which file are we working with?
		Set objFile = objFiles.Item(intCounter)
	
		' Where can we download it?
		Dim strTemporaryFilePath: strTemporaryFilePath = objFSO.BuildPath(strTempFolderPath, objFSO.GetTempName()) & "." & objFile.Extension

		' Download the file.
		Vault.ObjectFileOperations.DownloadFile objFile.ID, objFile.Version, strTemporaryFilePath

		' Create an object source file for this temporary file.
		Dim objObjectSourceFile: Set objObjectSourceFile = CreateObject("MFilesAPI.SourceObjectFile")
		objObjectSourceFile.Extension = objFile.Extension
		objObjectSourceFile.SourceFilePath = strTemporaryFilePath
		objObjectSourceFile.Title = objFile.Title

		' Add it to the collection.
		objSourceFiles.Add -1, objObjectSourceFile

	Next

	' Return the temporary files.
	Set GetNewObjectSourceFiles = objSourceFiles

End Function

' Clears temporary files.
Sub ClearTemporaryFiles(objObjectSourceFiles)

	' Iterate over the files and download each in turn.
	Dim intCounter, objFile
	For intCounter = 1 To objObjectSourceFiles.Count
		
		' Which file are we working with?
		Set objFile = objObjectSourceFiles.Item(intCounter)
		
		' If it exists, try and delete it.
		If objFSO.FileExists(objFile.SourceFilePath) Then
			On Error Resume Next
			objFSO.DeleteFile objFile.SourceFilePath, True
			On Error Goto 0
		End If

	Next

End Sub

 

  • Hello,

    Please provide the line on which the error is thrown.

  • that's a problem I Can't find it :(

    CoScriptObjectFactory.cpp, 465, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    ScriptErrorHelper.cpp, 96, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    MDispatchExImpl.h, 694, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    MDispatchExImpl.h, 994, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    MetadataCardAction.cpp, 386, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    MetadataCardAction.cpp, 570, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    MetadataEditor.cpp, 2959, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    MetadataModel.cpp, 4244, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    MetadataModel.cpp, 4681, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    ElectronicSignatureUIHelper.cpp, 235, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    MetadataModel.cpp, 12170, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    CoVaultMountingDocumentOperations.cpp, 3204, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    DocumentCache.cpp, 11300, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    DocumentCache.cpp, 11409, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    DocumentCache.cpp, 19577, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    RPCMethodCallWithRetry.h, 35, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    RPCMethodCallWithRetry.h, 35, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    RPCDocumentOperations.cpp, 12873, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    RPCDocumentOperations.cpp, 7387, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    MCallInLoop.h, 712, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 4158, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 3719, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 9397, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 10064, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    RPCDocumentOperationsHelper.cpp, 27741, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    RPCDocumentOperationsHelperPrivate.cpp, 2908, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    RPCDocumentOperationsHelperPrivate.cpp, 3120, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    RPCDocumentOperationsHelperPrivate.cpp, 3540, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    RPCDocumentOperationsHelperPrivate.cpp, 4379, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    VaultScriptSessionTemplates.cpp, 269, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    VaultScriptSessionTemplates.cpp, 328, Script execution failed. ((PUBLISHED, StateAction: 85-3)) (0x800408BB)
    VaultScriptSessionTemplates.cpp, 328, The value "-1" does not exist, or it is a conflict object. (0x800408E8)
    VaultScriptSessionTemplates.cpp, 510, The value "-1" does not exist, or it is a conflict object. (0x800408E8)
    CoActiveScriptSite.cpp, 895, The value "-1" does not exist, or it is a conflict object. (0x800408E8)
    CoActiveScriptSite.cpp, 737, The value "-1" does not exist, or it is a conflict object. (0x800408E8)
    PUBLISHED, StateAction, 30, The value "-1" does not exist, or it is a conflict object. (0x800408E8)
    CoVaultObjectOperations.cpp, 2552, The value "-1" does not exist, or it is a conflict object. (0x800408E8)
    ServerVaultObjectOperationsHelper.cpp, 1135, The value "-1" does not exist, or it is a conflict object. (0x800408E8)
    ServerVaultObjectOperationsHelper.cpp, 1340, The value "-1" does not exist, or it is a conflict object. (0x800408E8)
    ServerVaultObjectOperationsHelper.cpp, 1506, The value "-1" does not exist, or it is a conflict object. (0x800408E8)
    CoRPCOverCOM.cpp, 6141, The value "-1" does not exist, or it is a conflict object. (0x800408E8)
    RPCDocumentOperations.cpp, 8533, The value "-1" does not exist, or it is a conflict object. (0x800408E8)
    MCallInLoop.h, 712, The value "-1" does not exist, or it is a conflict object. (0x800408E8)
    RPCDocumentOperationsHelper.cpp, 477, The value "-1" does not exist, or it is a conflict object. (0x800408E8)
    RPCDocumentOperationsHelperPrivate.cpp, 8811, The value "-1" does not exist, or it is a conflict object. (0x800408E8)
    RPCDocumentOperationsHelperPrivate.cpp, 9591, The value "-1" does not exist, or it is a conflict object. (0x800408E8)
    (M-Files 21.9.10629.5)

  • HI,

    there is no info about it in error message. Or I can’t find it.

    Sorry for pasting image but when i send error as text is't reported as a abuse :(

  • Well the error is on line 30 of the script which means:

    Vault.ObjectOperations.CreateNewObjectExQuick ObjVer.Type, objNewObjectPropertyValues, objNewObjectSourceFiles, bolIsSingleFileDocument, True, CreateObject("MFilesAPI.AccessControlList")

    It is pretty hard to understand further why the error is thrown.

    Try to change from CreateObject("MFilesAPI.AccessControlList") to null and see if it throws the same error"

    Vault.ObjectOperations.CreateNewObjectExQuick ObjVer.Type, objNewObjectPropertyValues, objNewObjectSourceFiles, bolIsSingleFileDocument, True, null