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

Convert Multi-file to single file without deleting documents within

Hi,

Is it possible to convert a multi-file document into single files without deleting the documents itself within the multi-file document? I was able to convert a MFD to single file when I deleted one of the documents. Is there any other ways? Thank you.

  • A single-file document can only contain a single file in it like the name suggests, so if you convert a multi-file document into a single-file document there can be only one file. What is it that you are actually looking to achieve? That the files in the multi-file document would be stored in the vault as several single-file documents, each with their own document ID and set of metadata?

    If that's your goal, I don't believe there is any built-in functionality to do this but it should be doable as a custom extension. Depending on your exact use case you could for instance use a workflow for this so that a script would split the multi-file document in a certain workflow state or add a custom command to the desktop client UI if your users should be able to do this on an ad hoc basis.

  • I would also be interested in that use case...if anyone has already a solution for it.

  • It is relatively simple to create a script to split up files and place them in individual documents with a clone of the original document's metadata. If there can be many files to handle you may run into a timeout error on the server. The script below has a limit of 10 files to be split out in one run to avoid this. The workflow has a pause state and will repeat the process after 1 hour to handle the next batch if relevant.

    ' Split multifile documents into multiple singlefile documents
    ' Will not work in Event Handler, use in Workflow
    ' Will handle batches of max 10 files at a time to avoid scripting timeout.
    ' 1) identify all files attached to the multifiledocument
    ' 2) move those files into multiple singlefile documents while cloning properties
    ' 20220310 Karl Lausten
    Option Explicit
    ' Only run on documents.
    if ObjVer.Type = 0 Then
    	Dim oPropVals : Set oPropVals = Vault.ObjectPropertyOperations.GetProperties( ObjVer, True )
    	' only run on multifile documents (property 22 is False)
    	if oPropVals.SearchForProperty(22).TypedValue.Value = False then
    		Dim objFiles, objFile
    		Set objFiles = Vault.ObjectFileOperations.GetFilesForModificationInEventHandler(ObjVer)
    		Dim szExt
    		Dim szName, szShortName, iLength, szLongName
    		Dim szID
    		Dim szVersion
    		Dim szPath
    		Dim iWFSdone : iWFSdone = Vault.WorkflowOperations.GetWorkflowStateIDbyAlias("WFS.SplitMultifileDocs.Done")
    		Dim oNewPropVals : Set oNewPropVals = oPropVals.Clone()
    		' Set SingleFile and Workflow State on new documents
    		oNewPropVals.SearchForProperty(22).TypedValue.SetValue MFDataTypeBoolean, True
    		oNewPropVals.SearchForProperty(39).TypedValue.SetValue MFDataTypeLookup, iWFSdone
    		Dim oSourceObjectFile : Set oSourceObjectFile = CreateObject("MFilesAPI.SourceObjectFile")
    		Dim fso : Set fso = CreateObject("Scripting.FileSystemObject")
    		' Iterate over the files and move all but the first.
    		' if there are many files then limit the operation and repeat later.
    		Dim intCount, intCountMax,szRepeat
    		'err.raise mfscriptcancel, objFiles.Count
    		If objFiles.Count > 0 then
    			if objFiles.Count > 11 then
    				intCountMax = 11
    				szRepeat = 1
    			else	
    				intCountMax = objFiles.Count
    				szRepeat = 0
    			end if
    			'err.raise mfscriptcancel, objFiles.Count & ", " & intCountMax & ", " & szRepeat
    			For intCount = 2 To intCountMax
    				' Get a reference to the file in the collection.
    				Set objFile = objFiles.Item(intCount)
    				' Move the file.
    				szExt = objFile.Extension 
    				szName = objFile.GetNameForFileSystem()
    				'szLongName = objFile.Title
    				szID = objFile.ID
    				szVersion = objFile.Version - 1
    				szPath = "D:\Temp\EventHandler\" & szName	' Target path
    				' Download the file. The path must be available on the server!
    				Vault.ObjectFileOperations.DownloadFile szID, szVersion, szPath	
    				'Prepare file properties 
    				'Use file name as document name
    				iLength = InstrRev(szName,".") - 1 'looking for the end of the filename prior to the extension
    				szShortName = Left(szName,iLength) 'selecting the desired part of the filename
    				oSourceObjectFile.Extension = szExt
    				oSourceObjectFile.SourceFilePath = szPath
    				oSourceObjectFile.Title = szShortName
    				'Create new object while using cloned properties and the file copy.
    				Vault.ObjectOperations.CreateNewSFDObject 0, oNewPropVals, oSourceObjectFile, true, nothing 
    				fso.DeleteFile szPath											'Delete file from temp directory
    				'Vault.ObjectOperations.CheckIn oNewObjVersAndProps.ObjVer		'Check in the new object
    				'Remove the file from this object
    				Vault.ObjectFileOperations.RemoveFile ObjVer, objFile.FileVer
    			Next
    			if szRepeat = 0 then
    				'only 1 file remains, set SingleFile
    				Dim SFProperty : set SFProperty = CreateObject("MFilesAPI.PropertyValue")
    				SFProperty.PropertyDef = 22 'Builtin SingleFile	Property
    				SFProperty.TypedValue.SetValue MFDatatypeBoolean, True
    				' Upgrade the properties for the object
    				Vault.ObjectPropertyOperations.SetProperty ObjVer, SFProperty
    			Else
    				'need to pause the process to make sure it completes within given time restrictions
    				'move this object back to Pause and let it repeat Split Files later for the remaining files
    				Dim iWFpause, iWFpauseState
    				Dim WFSProperty : set WFSProperty = CreateObject("MFilesAPI.PropertyValue")
    				iWFpauseState = Vault.WorkflowOperations.GetWorkflowStateIDbyAlias("WFS.SplitMultifileDocs.Pause")
    				WFSProperty.PropertyDef = 39 'Builtin Workflow State Property
    				WFSProperty.TypedValue.SetValue MFDataTypeLookup, iWFpauseState
    				' Upgrade the property for the object
    				Vault.ObjectPropertyOperations.SetProperty ObjVer, WFSProperty
    			End if
    		End if
    	End if
    End if

  • Hi Joonas,

    The client wants to be able to do different actions in the files within the multi-file document that are in a workflow. I think using a script is the way to go. Thanks Joonas and birght-ideas.dk