Deleting MSG from Multi-File and convert to Single-File

Hy!

I am using the external Connector to M365 to read Mails from a scan device. This mails have exactly one PDF attached. Is it possible to create a Workflow with a script to delete the MSG File from the Multi-File and convert the PDF to a Single File?

Does anyone has such a script?

Thank you for your Inputs

Willi

Parents
  • Hi Willi,

    That is certainly possible. Craig Hawker helped me create this script 7 or 8 years ago.
    Please note that scripts will be deprecated at some point. Microsoft has announced that their support for vb script will be discontinued. If you are looking for a long term solution, you should consider other solutions.

    Option Explicit
    ' script for EventHandler or WF Action, purpose to remove .msg file from multifile document after import of mail with attached document.
    ' the vault must include a boolean property with Alias "M-Files.Property.StripMsgFilesOnSave" and value = True 
    ' Should go in BeforeCheckInChangesFinalize Eventhandler or in WF Action script
    
    ' Declare the aliases that we will look up later.
    Const strStripMsgFilesOnSavePropertyAlias = "M-Files.Property.StripMsgFilesOnSave"
    
    ' Look up the aliases.
    Dim intStripMsgFilesOnSavePropertyId
    intStripMsgFilesOnSavePropertyId = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("M-Files.Property.StripMsgFilesOnSave")
    
    ' Get the property values.
    Dim objPropertyValues
    Set objPropertyValues = Vault.ObjectPropertyOperations.GetProperties(ObjVer)
    
    ' Does the object have the "strip msg files" property?
    Dim objStripMsgFilesPropertyValue
    Set objStripMsgFilesPropertyValue = objPropertyValues.SearchForPropertyEx(intStripMsgFilesOnSavePropertyId, true)
    
    ' Only do this if it's a MFD and has the property.
    If Not (objStripMsgFilesPropertyValue Is Nothing) AND False = Vault.ObjectOperations.IsSingleFileObject(ObjVer) Then
    
    	' Only continue if it has the property and the value is true.
    	If (False = objStripMsgFilesPropertyValue.Value.IsEmpty() AND False = objStripMsgFilesPropertyValue.Value.IsNULL() AND objStripMsgFilesPropertyValue.Value.Value = true) Then
    		
    		' If it does then we need to deal with the files.
    		' Retrieve the files for this object version.
    		Dim objFiles
    		Set objFiles = Vault.ObjectFileOperations.GetFilesForModificationInEventHandler(ObjVer)
    
    		' Iterate over the files and remove the msg ones.
    		Dim intRemainingFilesCount
    		intRemainingFilesCount = objFiles.Count
    
    		Dim intCount
    		For intCount = 1 To objFiles.Count
    			
    			' Get a reference to the file in the collection.
    			Dim objFile
    			Set objFile = objFiles.Item(intCount)
    
    			' Ignore non-msg files.
    			If LCase(objFile.Extension & "") = "msg" Then
    
    				' Remove the msg file.
    				Vault.ObjectFileOperations.RemoveFile ObjVer, objFile.FileVer
    			
    				' Reduce the number of files remaining.
    				intRemainingFilesCount = intRemainingFilesCount - 1
    
    			End If
    
    		Next
    
    		' If the object only has one file remaining (and was not a SFD), set it to a SFD.
    		If (1 = intRemainingFilesCount) Then
    			Vault.ObjectOperations.SetSingleFileObject ObjVer, True
    		End If 
    		
    		' Remove the property.
    		Vault.ObjectPropertyOperations.RemoveProperty ObjVer, intStripMsgFilesOnSavePropertyId
    
    	End If
    
    End If

Reply
  • Hi Willi,

    That is certainly possible. Craig Hawker helped me create this script 7 or 8 years ago.
    Please note that scripts will be deprecated at some point. Microsoft has announced that their support for vb script will be discontinued. If you are looking for a long term solution, you should consider other solutions.

    Option Explicit
    ' script for EventHandler or WF Action, purpose to remove .msg file from multifile document after import of mail with attached document.
    ' the vault must include a boolean property with Alias "M-Files.Property.StripMsgFilesOnSave" and value = True 
    ' Should go in BeforeCheckInChangesFinalize Eventhandler or in WF Action script
    
    ' Declare the aliases that we will look up later.
    Const strStripMsgFilesOnSavePropertyAlias = "M-Files.Property.StripMsgFilesOnSave"
    
    ' Look up the aliases.
    Dim intStripMsgFilesOnSavePropertyId
    intStripMsgFilesOnSavePropertyId = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("M-Files.Property.StripMsgFilesOnSave")
    
    ' Get the property values.
    Dim objPropertyValues
    Set objPropertyValues = Vault.ObjectPropertyOperations.GetProperties(ObjVer)
    
    ' Does the object have the "strip msg files" property?
    Dim objStripMsgFilesPropertyValue
    Set objStripMsgFilesPropertyValue = objPropertyValues.SearchForPropertyEx(intStripMsgFilesOnSavePropertyId, true)
    
    ' Only do this if it's a MFD and has the property.
    If Not (objStripMsgFilesPropertyValue Is Nothing) AND False = Vault.ObjectOperations.IsSingleFileObject(ObjVer) Then
    
    	' Only continue if it has the property and the value is true.
    	If (False = objStripMsgFilesPropertyValue.Value.IsEmpty() AND False = objStripMsgFilesPropertyValue.Value.IsNULL() AND objStripMsgFilesPropertyValue.Value.Value = true) Then
    		
    		' If it does then we need to deal with the files.
    		' Retrieve the files for this object version.
    		Dim objFiles
    		Set objFiles = Vault.ObjectFileOperations.GetFilesForModificationInEventHandler(ObjVer)
    
    		' Iterate over the files and remove the msg ones.
    		Dim intRemainingFilesCount
    		intRemainingFilesCount = objFiles.Count
    
    		Dim intCount
    		For intCount = 1 To objFiles.Count
    			
    			' Get a reference to the file in the collection.
    			Dim objFile
    			Set objFile = objFiles.Item(intCount)
    
    			' Ignore non-msg files.
    			If LCase(objFile.Extension & "") = "msg" Then
    
    				' Remove the msg file.
    				Vault.ObjectFileOperations.RemoveFile ObjVer, objFile.FileVer
    			
    				' Reduce the number of files remaining.
    				intRemainingFilesCount = intRemainingFilesCount - 1
    
    			End If
    
    		Next
    
    		' If the object only has one file remaining (and was not a SFD), set it to a SFD.
    		If (1 = intRemainingFilesCount) Then
    			Vault.ObjectOperations.SetSingleFileObject ObjVer, True
    		End If 
    		
    		' Remove the property.
    		Vault.ObjectPropertyOperations.RemoveProperty ObjVer, intStripMsgFilesOnSavePropertyId
    
    	End If
    
    End If

Children
No Data