Adding Multiple Values to a Single Property Field via Event Handler Search

Hello,

The current scenario is that an order has been placed and there are a number of commissions that need to be tied to this order. I've tried to create an event handler with limited success. It is able to grab one of the many commissions but not all. Would anyone happen to know how to achieve this?

I've attached the event handler and the current output to this post.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
option Explicit
If ObjVer.Type = 111 Then
Dim PDSOPOrder, OTSOPNumberOrder, OTCommission, ValueSOPNumberOrder, CLOrder, PDSOPNumberOrder, PDCommission
OTSOPNumberOrder = Vault.ObjectTypeOperations.GetObjectTypeIDByAlias("OT.SopNumberOrders")
OTCommission = Vault.ObjectTypeOperations.GetObjectTypeIDByAlias("OT.Commission")
PDSOPOrder = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("PD.OrderNumber")
CLOrder = Vault.ClassOperations.GetObjectClassIDByAlias("CL.Order")
PDSOPNumberOrder = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("PD.SOPNumberOrder")
PDCommission = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("PD.Commission")
Dim PropertyValues : Set PropertyValues = Vault.ObjectPropertyOperations.GetProperties(objver)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Parents
  • You would have to create a list of lookups as a variable. Then in your For Each loop you should add the result to that list. When done you use the list as input to the property value. There is a trick to this that Craig Hawker once taught me, but right now I can't recall it.

    Craig, you are a fair bit  younger - please help us out here....

  • Damnit, put me on the spot Karl... Joy

    I don't recall a trick.  There are some helper methods in C#, which I would use for new code in any vault these days (as Microsoft has said it'll stop supporting VBScript at some point, so implementing new VBScript is not something I'd recommend).

    But this should work:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    ' Add all items to the lookups.
    Dim oLookups: Set oLookups = CreateObject("MFilesAPI.Lookups")
    For Each oSearchResults In oSearchResults
    oLookups.Add -1, oSearchResults.ObjVer.ID
    Next
    ' Set the value.
    PropertyValue.TypedValue.SetValueToMultiSelectLookup oLookups
    Vault.ObjectPropertyOperations.SetProperty ObjVer, PropertyValue
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Some points:

    • The lookups collection contains all items you want on the property
    • The setting of the property value is moved outside the loop
Reply
  • Damnit, put me on the spot Karl... Joy

    I don't recall a trick.  There are some helper methods in C#, which I would use for new code in any vault these days (as Microsoft has said it'll stop supporting VBScript at some point, so implementing new VBScript is not something I'd recommend).

    But this should work:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    ' Add all items to the lookups.
    Dim oLookups: Set oLookups = CreateObject("MFilesAPI.Lookups")
    For Each oSearchResults In oSearchResults
    oLookups.Add -1, oSearchResults.ObjVer.ID
    Next
    ' Set the value.
    PropertyValue.TypedValue.SetValueToMultiSelectLookup oLookups
    Vault.ObjectPropertyOperations.SetProperty ObjVer, PropertyValue
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

    Some points:

    • The lookups collection contains all items you want on the property
    • The setting of the property value is moved outside the loop
Children
  • It is saying "Type mismatch: add".

  • Oh yes, of course.  The Lookups collection expects a Lookup.

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    ' Add all items to the lookups.
    Dim oLookups: Set oLookups = CreateObject("MFilesAPI.Lookups")
    For Each oSearchResults In oSearchResults
    Dim oLookup: Set oLookup = CreateObject("MFilesAPI.Lookup")
    oLookup.Item = oSearchResults.ObjVer.ID
    oLookups.Add -1, oLookup
    Next
    ' Set the value.
    PropertyValue.TypedValue.SetValueToMultiSelectLookup oLookups
    Vault.ObjectPropertyOperations.SetProperty ObjVer, PropertyValue
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX