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

VBA - How to assign an object (from search) to a lookup property

Dear community,

I struggle to assign an object (that I retrieved through a search) to a property. This is basically what I am trying to do:

- I have a class with a property x (single select of object of type aaaa)
- I read the object of type aaaa with a search condition and I can successfully retrieve the object I want
- I do not really understand how to assign the retrieved object to the property x

Below the code I have written so far.



    ' create search condition
  oSearchCondition.ConditionType = MFilesAPI.MFConditionType.MFConditionTypeContains
  oSearchCondition.Expression.DataPropertyValuePropertyDef = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("prop.Something")
  oSearchCondition.TypedValue.SetValue MFilesAPI.MFDataType.MFDatatypeText, "MY SEARCH TERM"
 
  ' Invoke the search operation.
  Dim oObjectVersions As New MFilesAPI.ObjectSearchResults
  Set oObjectVersions = Vault.ObjectSearchOperations.SearchForObjectsByCondition(oSearchCondition, False)
 
  ' --> this returns the object I want successfully.... (oObjectVersions(1))
 
  ' Creation of lookup object and assigning found object to it.
  Dim oLookup: Set oLookup = CreateObject("MFilesAPI.Lookup")
  oLookup.ObjectType = 115 ' ID of object type of retrieved object
  oLookup.Item = ???????????????? ' what to assign here??????????????? assigning oObjectVersions(1) wouldn't work because of wrong type..
 
  'Getting X property
  Dim objXProp As New MFilesAPI.PropertyValue
  Set objXProp = PropertyValues.SearchForPropertyByAlias(Vault, PROPDEF_X, True)
  objXProp.Value.SetValueToLookup oLookup

 
  'Target object CheckOut
  Dim oObjVersionACO
  Set oObjVersionACO = Vault.ObjectOperations.CheckOut(ObjID)

  Vault.ObjectPropertyOperations.SetProperty ObjVer, oLookup

  'Target object CheckIn
  Vault.ObjectOperations.CheckIn (oObjVersionACO.ObjVer)



Can somebody help for the line with the many question marks??

Many thanks,
Beat