Dim oList: set oList = CreateObject("MFilesAPI.Lookups")
Dim oLookup: Set oLookup = CreateObject("MFilesAPI.Lookup")
dim oNewLookup: Set oNewLookup = CreateObject("MFilesAPI.Lookup")
oNewLookup.ObjectType = 0
Dim oDic : Set oDic = CreateObject("Scripting.Dictionary")
' create one or more searches to find the objects that you want to add to you property.
' values could also be fetched from a multiselect property on the same or a related object if relevant.
' if more than one search is required you need to make sure that the same result is not entered twice. Hence the use of a scripting dictionary. This is not needed in a single search configuration.
'Create a new list for each search, use TypedValue.GetValueAsLookups() on the search results.
'For each new list you need to check whether each item is already in the scripting dictionary, if not than add it to the final list.
'Sample code for objects found in a multiselect property (will add a specific version of the objects to the list):
Dim oList, oList1, oList2
set oList1 = oPropVals.SearchForProperty(iYourPropertyID).TypedValue.GetValueAsLookups()
If oList1.Count > 0 then
For each oLookup in oList1
oNewLookup.Item = oLookup.Item
oNewLookup.Version = oLookup.Version
If not oDic.Exists(oLookup.Item) then
oDic.Add oLookup.Item, oLookup.Version
OList.Add -1, oNewLookup
End if
Next
End if
' sample code for objects found in a search
Dim oOneSC: Set oOneSC = CreateObject("MFilesAPI.SearchCondition")
Dim oSCs: Set oSCs = CreateObject("MFilesAPI.SearchConditions")
' Deleted = no
oOneSC.ConditionType = MFConditionTypeEqual
oOneSC.Expression.DataStatusValueType = MFStatusTypeDeleted
oOneSC.TypedValue.SetValue MFDatatypeBoolean, False
oSCs.Add -1, oOneSC
' Object type = X
oOneSC.ConditionType = MFConditionTypeEqual
oOneSC.Expression.DataStatusValueType = MFStatusTypeObjectTypeID
oOneSC.TypedValue.SetValue MFDatatypeLookup, iOTX
oScs.Add -1, oOneSC'
'add other relevant search criteria
Dim oSearchResult, oSearchResults
Set oSearchResults = Vault.ObjectSearchOperations.SearchForObjectsByConditions(oScs, MFSearchFlagNone, False)
'In my case I need to retrieve objects from a multiselect property on the objects found by the above search.
'This property is automatically updated via Compliance Kit, Managed Properties, therefor I have to make sure it is updated before I use the results.
If oSearchResults.count > 0 then
Dim oXObjID, szBuildVar, oObjectVersionAndProperties, oAObjVer, oBObjVer, oBVersionX, oBProp, oBProps, oPropVals, oADocs, thisProperty
For each oSearchResult in oSearchResults
' Update the managed properties for the object where necessary
set oObjectVersionAndProperties = vault.ObjectOperations.GetObjectVersionAndProperties(oSearchResult.ObjVer, True)
set oXObjID = oSearchResult.ObjVer.ObjID
if not oObjectVersionAndProperties.VersionData.ObjectCheckedOut then
szBuildVar = "["& Chr(34) & "UpdateAutomaticProperties" & Chr(34) &", " & Chr(34) & "(" & CStr( oXObjID.Type ) & "-" & CStr( oXObjID.ID ) & ")" & Chr(34) & "]"
Vault.ExtensionMethodOperations.ExecuteVaultExtensionMethod "MFiles.ComplianceKit.MFEventHandlerVaultExtensionMethod", szBuildVar
end if
'Get referenced documents from the updated objects and change link to fixed version.
Set oAObjVer = Vault.ObjectOperations.GetLatestObjVer(oXObjID,False,True)
Set oPropVals = Vault.ObjectPropertyOperations.GetProperties( oAObjVer, True )
Set oADocs = oPropVals.SearchForProperty(iPDRefdByDocs).TypedValue.GetValueAsLookups()
if Not oADocs.count = 0 then
For Each oADoc In oADocs
if not oAdoc.Deleted = True then
' Set to current version instead of -1, then add to list for further processing
oObjID.SetIDs 0, oADoc.Item '0 = object type Document
Set oBObjVer = Vault.ObjectOperations.GetLatestObjVer(oObjID,False,True)
oBVersionX = oBObjver.VersionEx.Version
oBProp.Item = oADoc.Item
oBProp.Version = oBVersionX
oBProps.Add -1, oBProp
End if
Next
'Set the found values to the list
thisProperty.TypedValue.SetValueToMultiSelectLookup oBProps
set oList2 = thisProperty.TypedValue.GetValueAsLookups()
If oList2.Count > 0 then
For each oLookup in oList2
oNewLookup.Item = oLookup.Item
oNewLookup.Version = oLookup.Version
If not oDic.Exists(oLookup.Item) then
oDic.Add oLookup.Item, oLookup.Version
OList.Add -1, oNewLookup
End if
Next
End if
end if
Next
Output = oList
Dim oList: set oList = CreateObject("MFilesAPI.Lookups")
Dim oLookup: Set oLookup = CreateObject("MFilesAPI.Lookup")
dim oNewLookup: Set oNewLookup = CreateObject("MFilesAPI.Lookup")
oNewLookup.ObjectType = 0
Dim oDic : Set oDic = CreateObject("Scripting.Dictionary")
' create one or more searches to find the objects that you want to add to you property.
' values could also be fetched from a multiselect property on the same or a related object if relevant.
' if more than one search is required you need to make sure that the same result is not entered twice. Hence the use of a scripting dictionary. This is not needed in a single search configuration.
'Create a new list for each search, use TypedValue.GetValueAsLookups() on the search results.
'For each new list you need to check whether each item is already in the scripting dictionary, if not than add it to the final list.
'Sample code for objects found in a multiselect property (will add a specific version of the objects to the list):
Dim oList, oList1, oList2
set oList1 = oPropVals.SearchForProperty(iYourPropertyID).TypedValue.GetValueAsLookups()
If oList1.Count > 0 then
For each oLookup in oList1
oNewLookup.Item = oLookup.Item
oNewLookup.Version = oLookup.Version
If not oDic.Exists(oLookup.Item) then
oDic.Add oLookup.Item, oLookup.Version
OList.Add -1, oNewLookup
End if
Next
End if
' sample code for objects found in a search
Dim oOneSC: Set oOneSC = CreateObject("MFilesAPI.SearchCondition")
Dim oSCs: Set oSCs = CreateObject("MFilesAPI.SearchConditions")
' Deleted = no
oOneSC.ConditionType = MFConditionTypeEqual
oOneSC.Expression.DataStatusValueType = MFStatusTypeDeleted
oOneSC.TypedValue.SetValue MFDatatypeBoolean, False
oSCs.Add -1, oOneSC
' Object type = X
oOneSC.ConditionType = MFConditionTypeEqual
oOneSC.Expression.DataStatusValueType = MFStatusTypeObjectTypeID
oOneSC.TypedValue.SetValue MFDatatypeLookup, iOTX
oScs.Add -1, oOneSC'
'add other relevant search criteria
Dim oSearchResult, oSearchResults
Set oSearchResults = Vault.ObjectSearchOperations.SearchForObjectsByConditions(oScs, MFSearchFlagNone, False)
'In my case I need to retrieve objects from a multiselect property on the objects found by the above search.
'This property is automatically updated via Compliance Kit, Managed Properties, therefor I have to make sure it is updated before I use the results.
If oSearchResults.count > 0 then
Dim oXObjID, szBuildVar, oObjectVersionAndProperties, oAObjVer, oBObjVer, oBVersionX, oBProp, oBProps, oPropVals, oADocs, thisProperty
For each oSearchResult in oSearchResults
' Update the managed properties for the object where necessary
set oObjectVersionAndProperties = vault.ObjectOperations.GetObjectVersionAndProperties(oSearchResult.ObjVer, True)
set oXObjID = oSearchResult.ObjVer.ObjID
if not oObjectVersionAndProperties.VersionData.ObjectCheckedOut then
szBuildVar = "["& Chr(34) & "UpdateAutomaticProperties" & Chr(34) &", " & Chr(34) & "(" & CStr( oXObjID.Type ) & "-" & CStr( oXObjID.ID ) & ")" & Chr(34) & "]"
Vault.ExtensionMethodOperations.ExecuteVaultExtensionMethod "MFiles.ComplianceKit.MFEventHandlerVaultExtensionMethod", szBuildVar
end if
'Get referenced documents from the updated objects and change link to fixed version.
Set oAObjVer = Vault.ObjectOperations.GetLatestObjVer(oXObjID,False,True)
Set oPropVals = Vault.ObjectPropertyOperations.GetProperties( oAObjVer, True )
Set oADocs = oPropVals.SearchForProperty(iPDRefdByDocs).TypedValue.GetValueAsLookups()
if Not oADocs.count = 0 then
For Each oADoc In oADocs
if not oAdoc.Deleted = True then
' Set to current version instead of -1, then add to list for further processing
oObjID.SetIDs 0, oADoc.Item '0 = object type Document
Set oBObjVer = Vault.ObjectOperations.GetLatestObjVer(oObjID,False,True)
oBVersionX = oBObjver.VersionEx.Version
oBProp.Item = oADoc.Item
oBProp.Version = oBVersionX
oBProps.Add -1, oBProp
End if
Next
'Set the found values to the list
thisProperty.TypedValue.SetValueToMultiSelectLookup oBProps
set oList2 = thisProperty.TypedValue.GetValueAsLookups()
If oList2.Count > 0 then
For each oLookup in oList2
oNewLookup.Item = oLookup.Item
oNewLookup.Version = oLookup.Version
If not oDic.Exists(oLookup.Item) then
oDic.Add oLookup.Item, oLookup.Version
OList.Add -1, oNewLookup
End if
Next
End if
end if
Next
Output = oList
© 2024 M-Files, All Rights Reserved.