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

VBScript Event Handler to set PropertyDef of related Object

I'm currently working on an event handler, BeforeCheckInChangesFinalized, that will use a PropertyValue of the current object to look up an associated object, and then update a PropertyValue on the associated object. Our data model has a 'Member' object and 'Document' object where a Documents are children to a Member. This relationship is created with the 'Member' property which is a look up to our list of members and is present on all of our Document classes. Our Document Classes are all medical documents and one of our business units has requested that we display the Document Date (Essentially the effective date of the document) of business critical documents on an associated member's metadata card. For example if I have a document class 'LCED Initial' with a Document Date of 6/2/2023 and that is related to the member Murphy, Zachary the unit would like 6/2/2023 to populate into the 'LCED Date' field to be viewable on the Member's metadata card. I've used some previous posts on this forum as a jumping off point and I have a script that *seems* to run, but doesn't actually do anything:

Fullscreen
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Option Explicit
' get property values of the owner object
Dim oDocPropVals : Set oDocPropVals = Vault.ObjectPropertyOperations.GetProperties (ObjVer,False)
'
DIM oComments, szDocumentDate, oMember, iMember
' Get DisplayID of 'Member' and 'Document Date' fields of current Document
iOwner = oPropVals.SearchForPropertyByAlias(vault,"M-Files.Property.Member",True).TypedValue.GetValueAsLookups.Item(0).Item
szDocumentDate = oPropVals.SearchForPropertyByAlias(vault,"MF.PD.DocumentDate",True).TypedValue.GetValueAsUnLocalizedText
' Get most recent version of the iMember object
Set oMember = Vault.ObjectOperations.GetLatestObjVer(iMember, True, false)
'Checkout the object you want to update
Dim checkedOutObjectVersion : Set checkedOutObjectVersion = vault.ObjectOperations.CheckOut(oMember.ObjVer.objID)
'update properties of checked out object
Dim oMemberPropVals : Set oMemberPropVals = Vault.ObjectPropertyOperations.GetProperties(checkedOutObjectVersion, False)
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 

Now, I'm admittedly a self taught Python Developer and I'm relatively new to M-Files (I've been working with M-Files for almost a year now) so please excuse my poor coding skills and notion as I'm new to VBS. Also there might be a better way to do this so if that's the case I'm open to suggestions. However, as a caveat to this the Document Classes aren't unique to an individual member. So a member might have more than one 'LCED Initial' document. My plan is to add some additional checks to always use the greatest date value for the associated field, but I'm struggling to get this initial code running. Any input is greatly appreciated! 

Parents
  • maybe change in line 14 iMember for iOwner? 

  • Oversight on my end. I don't actually have iOwner initialized anywhere so line 10 should be iMember. However, even with that change, the handler will execute, but nothing happens. 

  • You will have to add the code also for the case a new document is created.

    I would use 

    AfterCreateNewObjectFinalize 

    AfterCheckInChanges 

    also make sure the code is executed just for your LCED Initial class:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Option Explicit
    Dim iClass: iclass = PropertyValues.SearchForProperty(100).TypedValue.GetValueAsLookup.Item
    on error resume next
    if iclass = 114 then '' change it to Id of LCED Initial class you can get it also via class alias
    on error goto 0
    ''' your code
    end if
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Reply
  • You will have to add the code also for the case a new document is created.

    I would use 

    AfterCreateNewObjectFinalize 

    AfterCheckInChanges 

    also make sure the code is executed just for your LCED Initial class:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Option Explicit
    Dim iClass: iclass = PropertyValues.SearchForProperty(100).TypedValue.GetValueAsLookup.Item
    on error resume next
    if iclass = 114 then '' change it to Id of LCED Initial class you can get it also via class alias
    on error goto 0
    ''' your code
    end if
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Children