Home
About
Search
Welcome to M-Files Empower – our new support experience. We'd love to hear what you think!Give feedback
Home

VBscript: Create MD5 hash from property value in M-Files

Last updated on 28 September 2023

COM API

Overview

Please note that scripting is not part of standard support, and this is just an example script to show how to use the API. Be aware that all scripts are run at your own risk.

Sometimes creating a hash value from a property value can be useful. For example, if you are using Compliance Kit - Unique Object Enforcement, and you would need to add a multi-line text property among the unique properties. Adding a multi-line property as a unique property is not allowed, but you can work around this by calculating the property value hash and using that as the unique property.

Solution

Here is a simple VBscript sample that calculates an MD5 hash to a property value. This is set as the automatic value for the property where you want the hash to appear. I_PropToHash is the property which value you want to hash.

Please note that the script expects to find the property to hash on the metadata card.

Option Explicit

Dim oUTF8 : Set oUTF8 = CreateObject("System.Text.UTF8Encoding")

Dim oMD5 : set oMD5 = CreateObject("System.Security.Cryptography.MD5CryptoServiceProvider")

Dim I_PropToHash: I_PropToHash = 1265

Dim PropertyValues : Set PropertyValues = Vault.ObjectPropertyOperations.GetProperties( ObjVer, True)

Dim s : s = PropertyValues.SearchForProperty(I_PropToHash).TypedValue.DisplayValue

Dim hash : hash = oUTF8.GetBytes_4(s)

oMD5.Initialize()

hash = oMD5.ComputeHash_2((hash))

output = bytesToHex(hash)

Function bytesToHex(aBytes)

    Dim hexStr, x

    For x=1 To lenb(aBytes)

        hexStr= LCase(hex(ascb(midb( (aBytes) ,x,1))))

        if len(hexStr)=1 then hexStr="0" & hexStr

       bytesToHex=bytesToHex & hexStr

    Next

end Function

Still need help?

On this page