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 access value(s) from a different vault

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?

Parents
  • 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.GetValueAsUnlocalizedText

Reply
  • 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.GetValueAsUnlocalizedText

Children
  • Hi,

    This is because there must be a Desktop Client installed on the server and at least 1 connection configured on it.
    The advantage of the client connection is that there is no need to put a password explicitly in the script.
    The disadvantage is that it still has to be configured in the client.
    The script below illustrates how to make both a client-mode connection and a server-mode connection.
    In the second option, the disadvantage is that the user's password must be exposed in the script, and this user should have sys admin rights to be able to access the other vault without restrictions.
    This in itself is a security risk. So consider carefully which approach is more suitable for your task.
    '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.