Frequently Asked Questions
Frequently Asked Questions
M-Files API: how to search for anything pointing to a value list item
Posted by Henri Huhtamäki (M-Files) on 27 September 2019 01:58 PM

1     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.

2     Solution

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

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

(0 vote(s))
This article was helpful
This article was not helpful

Help Desk Software by Kayako case