I have two an object named Employee in VaultA, When working in VaultB I want to access Employee values (say Employee's name and end of cantract date) from VaultB. how do I do that using VBscript?
There doesn't seem to be a good way to access other Vaults from within the VBScript. I Attempted to instantiate a whole new ClientApplication object in the script so that I could obtain a connection to the other Vault. But no Connections were found. Perhaps thre is a bug someone else can identify or maybe a ServerApplication object would work better at compelling the connection? Alternatively maybe there is some Built-In object that is available to use that isn't in the documentation? Anyway, my script always fails when I check for the Connection Count to the other Vault because I receive 0 connections.
Option Explicit
'Which vault are we connecting to?
Dim vaultGuid
vaultGuid = "{B450458C-E27F-45D5-9920-64182A9B5AA2}" 'Other Vault
'Connect to the vault using a client connection.
' ref: http://developer.m-files.com/APIs/COM-API/#api-modes-client-vs-server
' Note: this code will just return the first connection to the vault.
Dim clientApplication 'As MFilesAPI.MFilesClientApplication
SET clientApplication = CreateObject("MFilesAPI.MFilesClientApplication")
Dim otherVault 'As MFilesAPI.Vault
Dim otherConnections 'As MFilesAPI.VaultConnections
set otherConnections = clientApplication.GetVaultConnectionsWithGUID(vaultGuid)
If otherConnections is Nothing Then
Err.Raise MFScriptCancel, "No Connections to the Other Vault"
end if
If otherConnections.Count < 1 Then
Err.Raise MFScriptCancel, Cstr(otherConnections.Count) & " Other Vault Connections"
End If
otherVault = otherConnections.Item(1).BindToVault(IntPtr.Zero, True, True)
If (otherVault Is Nothing) Then
Err.Raise MFScriptCancel, "Vault not bound"
End If
'Search for Item in the Other Vault
'Create the search condition.
Dim searchCondition 'As MFilesAPI.SearchCondition
set searchCondition = CreateObject("MFilesAPI.SearchCondition")
'We want to search by property - in this case the built-in "name or title" property.
'Alternatively we could pass the ID of the property definition if it's not built-in.
searchCondition.Expression.SetPropertyValueExpression MFilesAPI.MFBuiltInPropertyDef.MFBuiltInPropertyDefNameOrTitle, MFilesAPI.MFParentChildBehavior.MFParentChildBehaviorNone
'We want only items that equal the search string provided.
searchCondition.ConditionType = MFilesAPI.MFConditionType.MFConditionTypeEqual
'We want to search for items that are named "hello world".
'Note that the type must both match the property definition type, And be applicable for the
'supplied value.
searchCondition.TypedValue.SetValue MFilesAPI.MFDataType.MFDatatypeText, "text to find other vault object" 'TODO populate with the text from local property used to search for remote object
Dim searchResult 'As MFilesAPI.ObjectSearchResults
set searchResult = otherVault.ObjectSearchOperations.SearchForObjectsByCondition(searchCondition, False)
Dim otherPropertyValues 'As MFilesAPI.PropertyValues
Dim otherEmailPropertyValue 'As MFilesAPI.PropertyValue
If searchResult.Count > 0 Then
set otherPropertyValues = otherVault.ObjectPropertyOperations.GetProperties(searchResult.Item(1).ObjVer)
set otherEmailPropertyValue = otherPropertyValues.SearchForPropertyByAlias(otherVault, "M-Files.Property.Email", False) 'An Aliased property in my example
End If
Output = otherEmailPropertyValue.GetValueAsUnlocalizedTextThere doesn't seem to be a good way to access other Vaults from within the VBScript. I Attempted to instantiate a whole new ClientApplication object in the script so that I could obtain a connection to the other Vault. But no Connections were found. Perhaps thre is a bug someone else can identify or maybe a ServerApplication object would work better at compelling the connection? Alternatively maybe there is some Built-In object that is available to use that isn't in the documentation? Anyway, my script always fails when I check for the Connection Count to the other Vault because I receive 0 connections.
Option Explicit
'Which vault are we connecting to?
Dim vaultGuid
vaultGuid = "{B450458C-E27F-45D5-9920-64182A9B5AA2}" 'Other Vault
'Connect to the vault using a client connection.
' ref: http://developer.m-files.com/APIs/COM-API/#api-modes-client-vs-server
' Note: this code will just return the first connection to the vault.
Dim clientApplication 'As MFilesAPI.MFilesClientApplication
SET clientApplication = CreateObject("MFilesAPI.MFilesClientApplication")
Dim otherVault 'As MFilesAPI.Vault
Dim otherConnections 'As MFilesAPI.VaultConnections
set otherConnections = clientApplication.GetVaultConnectionsWithGUID(vaultGuid)
If otherConnections is Nothing Then
Err.Raise MFScriptCancel, "No Connections to the Other Vault"
end if
If otherConnections.Count < 1 Then
Err.Raise MFScriptCancel, Cstr(otherConnections.Count) & " Other Vault Connections"
End If
otherVault = otherConnections.Item(1).BindToVault(IntPtr.Zero, True, True)
If (otherVault Is Nothing) Then
Err.Raise MFScriptCancel, "Vault not bound"
End If
'Search for Item in the Other Vault
'Create the search condition.
Dim searchCondition 'As MFilesAPI.SearchCondition
set searchCondition = CreateObject("MFilesAPI.SearchCondition")
'We want to search by property - in this case the built-in "name or title" property.
'Alternatively we could pass the ID of the property definition if it's not built-in.
searchCondition.Expression.SetPropertyValueExpression MFilesAPI.MFBuiltInPropertyDef.MFBuiltInPropertyDefNameOrTitle, MFilesAPI.MFParentChildBehavior.MFParentChildBehaviorNone
'We want only items that equal the search string provided.
searchCondition.ConditionType = MFilesAPI.MFConditionType.MFConditionTypeEqual
'We want to search for items that are named "hello world".
'Note that the type must both match the property definition type, And be applicable for the
'supplied value.
searchCondition.TypedValue.SetValue MFilesAPI.MFDataType.MFDatatypeText, "text to find other vault object" 'TODO populate with the text from local property used to search for remote object
Dim searchResult 'As MFilesAPI.ObjectSearchResults
set searchResult = otherVault.ObjectSearchOperations.SearchForObjectsByCondition(searchCondition, False)
Dim otherPropertyValues 'As MFilesAPI.PropertyValues
Dim otherEmailPropertyValue 'As MFilesAPI.PropertyValue
If searchResult.Count > 0 Then
set otherPropertyValues = otherVault.ObjectPropertyOperations.GetProperties(searchResult.Item(1).ObjVer)
set otherEmailPropertyValue = otherPropertyValues.SearchForPropertyByAlias(otherVault, "M-Files.Property.Email", False) 'An Aliased property in my example
End If
Output = otherEmailPropertyValue.GetValueAsUnlocalizedTextHi,
'At Least M-Files Server Tools must be installed
MFVault = "MFVault" ' Name of Vault in M-Files Desktop Client Settings. Require for Client Connection
VaultGUID = "VaultGUID" ' VaultGUID Required for Server Connection
MFilesAdmin = "MFilesAdmin" ' At Least "Manage User Accounts" must be checked
MFilesAdminPass = "MFilesAdminPass" ' Password
MFilesBase = "MFilesBase" ' Hostname for local Windows User or Domain for AD User
MFProtocol = "MFProtocol" ' Default TCP/IP Protocol
MFServerAddress = "MFServerAddress" ' Hostname or IP address of M-Files Server
MFServerPort = "MFServerPort" ' Default RPC Port 2266
ClientMode = False ' Enable Client Mode)
'--------------------------------------------------------
'Create oVault Connection
'--------------------------------------------------------
If ClientMode Then
Dim oClientApp: Set oClientApp = CreateObject("MFilesAPI.MFilesClientApplication")
Set oVault = oClientApp.BindToVault(MFVault, 0, true, false)
Else
Dim oServerApp: set oServerApp = CreateObject("MFilesAPI.MFilesServerApplication")
oServerApp.Connect MFAuthTypeSpecificWindowsUser, MFilesAdmin, MFilesAdminPass, MFilesBase, MFProtocol , MFServerAddress , MFServerPort
Set oVault = oServerApp.LogInToVault(VaultGUID)
End If This was helpful. For Client Mode you need a client installed on the server that is accessible by the user. I had the Client installed but not for "Any User" once I made this change then the script was able to find connections to the other Vault. Now I just need to resolve why it never completes and locks my object.
© 2025 M-Files, All Rights Reserved.