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

How to prevent user from changing files of a document

We have a workflow where users can import receipts in M-Files and they are approved by several persons depending on the metadata. Changes of the files should not be allowed, but information is filled in the metadata during the workflow. The only solution I have found to prevent changes of the document files, is to check with a script in the AfterCheckInChanges event handler. The script checks if the files of the document have changed since the last version.
Dim objFiles: Set objFiles = Vault.ObjectFileOperations.GetFiles(ObjVer)
' During the creation of the object no test is necessary
if ObjVer.Version > 1 then
' Getting files of previous version
Dim ObjVerOld: Set ObjVerOld = ObjVer.Clone()
ObjVerOld.Version = ObjVerOld.Version-1
Dim objFilesOld: Set objFilesOld = Vault.ObjectFileOperations.GetFiles(ObjVerOld)

' If count of files differ then raise exception
if objFiles.Count <> objFilesOld.count then
Err.Raise MFScriptCancel, "Es k?nnen keine Dateien hinzugef?gt oder entfernt werden!"
end if

Dim found
For index = 1 To objFiles.Count
' If a file has a version greater 1 then it was changed => raise exception
if objFiles.Item(index).FileVer.Version <> 1 then
Err.Raise MFScriptCancel, "Es k?nnen keine Dateien ver?ndert werden!"
end if

' If the GUID of the file has changed then the file was replaced => raise exception
found = false
For indexOld = 1 To objFilesOld.Count
if objFiles.Item(index).FileGUID = objFilesOld.Item(indexOld).FileGUID then
found = true
Exit for
end if
Next
if found = false then
Err.Raise MFScriptCancel, "Es k?nnen keine Dateien ausgestauscht werden!"
end if
Next
end if

Is this the recommended solution or is there a simpler way to achive this behaviour?
Thanks for the help.
Parents Reply Children
No Data