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

M-Files API: how to search for anything pointing to a value list item

Last updated on 27 February 2021

COM API

Overview

If you have multiple properties using same value list and would like to find any object that has any of those properties set to a specific value list item, this is an example of how to achieve that.
 

Solution

This is done by using a typed value expression in the search.

https://www.m-files.com/api/documentation/latest/MFilesAPI~Expression.html

Here is a sample VBscript that you can use in event handler. The err.raise is commented away at the moment, it can be used to display search count for testing purposes.

In the example, value list used has ID 179 and the value item ID 3

Dim oSC: Set oSC = CreateObject("MFilesAPI.SearchCondition")

Dim oSCs: Set oSCs = CreateObject("MFilesAPI.SearchConditions")

Dim oSC2s: Set oSC2s = CreateObject("MFilesAPI.SearchConditions")

Dim oExp: Set oExp = CreateObject("MFilesAPI.Expression")

Dim oTV: Set oTV = CreateObject("MFilesAPI.TypedValue")

oExp.SetTypedValueExpression MFDatatypeLookup, 179, 0, nothing

oTV.SetValue MFDatatypeLookup, 3

oSC.Set oExp, MFConditionTypeEqual, oTV

oSCs.Add -1, oSC

oSC2s.Add -1, oSC

Dim oRelatedObjects, oOneRelatedObject

Set oRelatedObjects = Vault.ObjectSearchOperations.SearchForObjectsByConditions(oSCs, MFSearchFlagNone, False)

'err.raise mfscriptcancel, oRelatedObjects.Count

Still need help?

On this page