Finding Owner Object Properties in Validation Script


I've got a class of type "contact person" which has a property "email address". The contact person is a child object of the object "client", which has a property "domain".

I'm trying to validate the "email address" to ensure that the domain matches the "client" domain property. Is there any way in the validation script under the "contact person" to get the properties of the owner object?



  • So I managed to work this one out:

    Option Explicit
    ' get property values of the owner object
    Dim oPropVals : Set oPropVals = Vault.ObjectPropertyOperations.GetProperties (ObjVer,False)
    Dim email, domain, owner, ownerDomain, extractDomain, ownerObj
    ' this is the email address that we're checking
    email = PropertyValue.GetValueAsUnlocalizedText
    ' this is the owner object, in our case "1049" is Owner (Customer)
    owner = oPropVals.SearchForProperty(1049).TypedValue.GetValueAsLookup.Item
    Dim objID
    Set objID = CreateObject("MFilesAPI.ObjID")
    ' 106 is the ID of the 'client' object type, which holds the domain allowed for all employees of this customer
    Call objID.SetIDs( 106,  owner)
    Set ownerObj = Vault.ObjectOperations.GetLatestObjVer( objID, false, false )
    ' get the property values belonging to this contact person's employer (customer)
    Dim oOwnerPropVals: Set oOwnerPropVals = Vault.ObjectPropertyOperations.GetProperties (ownerObj,False)
    ' get the email domain property for the customer
    domain = oOwnerPropVals.SearchForProperty(1113).TypedValue.Value
    'extract domains for comparison, the persons domain is taken as all characters to the right of the first '@'
    extractDomain = right(email, Len(email) - InStr(email, "@"))
    ' only allow proceeding if this person's domain matches the customer domain
    IF (domain <> extractDomain) THEN
    	Err.Raise MFScriptCancel, "To ensure data security customer email addresses must match customer domain." + vbNewLine + "Customer Domain: " + domain + vbNewLine + "Email Address Domain: " + extractDomain
    END IF

    The short version though is that every new object type you create will have an associated built-in property called Owner (OBJECT NAME). The variable you are performing validation on will have this property, which then lets you get to the actual owner object itself, grab it's properties, and then you can do what you want!