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

[RESOLVED] Checking if specific PropertyValue is empty with VBScript

Former Member
Former Member
Hello! I'm new to both M-files and VBScript so bare with me here.
I wan't to check specific PropertyValue is empty with VBScript. I found sample code from user guide, but it doesn't specify where to get PropertyDef or PropertyValue.
Here's the example I'm talking about:

Option Explicit
Dim szPropertyName, szValue
szPropertyName = PropertyDef.Name
szValue = PropertyValue.GetValueAsUnlocalizedText
If Len( szValue ) < 10 Then
    Err.Raise MFScriptCancel, "The property """ & szPropertyName & """ must have a value of at least 10 characters."
End If


This is what I've been working with:

Option Explicit
Dim oProperty : Set oProperty = CreateObject("MFilesAPI.PropertyValue")
oProperty.PropertyDef = 1041
Dim oValue : Set oValue = CreateObject("MFilesAPI.PropertyValue")
oValue = PropertyValue.GetValueAsUnlocalizedText
If Len( oValue ) <= 0 Then
'Do stuff
End If


Running this script generates error Variable is undefined: 'PropertyValue' as expected, but how do I get the PropertyValue for specific property. Also how to check if it's empty?
  • Dear ravenholm,

    When you are using Automatic property validation (described in manual: www.m-files.com/.../Validation.html
    Then PropertyValue variable with value of current property defintion is already provided and you don't have to do anything to obtain value for it. Checking if property is empty is as simple as this:

    Option Explicit
    if PropertyValue.Value.IsNull() then
    Err.Raise MFScriptCancel, "The property is empty."
    end if


    Other PropertyValues are not available in validation code.
    If you need to find reference to another property you have multiple options.

    1. In case you just need one property, you could use GetProperty VaultObjectPropertyOperation


    Option Explicit
    'Vault, ObjVer are provided as described in manual. 1041 is ID of Property Definition witch value you are looking for.
    Dim MyOtherPropertyValue: set MyOtherPropertyValue = Vault.ObjectPropertyOperations.GetProperty( ObjVer, 1041)
    if MyOtherPropertyValue.Value.IsNull() then
    Err.Raise MFScriptCancel, "The MyOtherPropertyis empty."
    end if



    2. In case you might need more than one Propertyvalue or property may not exist on metadata card you could use GetProperties VaultObjectPropertyOperation


    Option Explicit

    'Get Property Values collection of current metadata card
    Dim PropertyValues: set PropertyValues= Vault.ObjectPropertyOperations.GetProperties( ObjVer)

    'It is better to use aliases than property definition id's developer.m-files.com/.../ so in this example I will use aliases instead of id's.
    CONST MY_OTHER_PROPERTY_ALIAS = "MFiles.PropertyDef.MyOtherProperty" 'Alias that you have to specify in M-Files Admin poperty definition advanced tab.
    CONST MY_ANOTHER_PROPERTY_ALIAS = "MFiles.PropertyDef.AnotherProperty"

    'Find property values by alias www.m-files.com/.../index.html
    dim MyOtherPropertyPV: set MyOtherPropertyPV = PropertyValues.SearchForPropertyByAlias(Vault, MY_OTHER_PROPERTY_ALIAS, true )
    dim MyAnotherPropertyPV: set MyAnotherPropertyPV= PropertyValues.SearchForPropertyByAlias(Vault, MY_ANOTHER_PROPERTY_ALIAS, true )


    if not MyOtherPropertyPV is Nothing then 'Check if property value exist on metadata card
    if MyOtherPropertyPV .Value.IsNull() then 'Check if property was filled
    Err.Raise MFScriptCancel, "The MyOtherProperty is empty." ' Show error message to user
    end if
    end if

    'Same with other PropertyValue
    if not MyAnotherPropertyPVis Nothing then
    if MyAnotherPropertyPV.Value.IsNull() then
    Err.Raise MFScriptCancel, "The MyAnotherPropertyPV is empty."
    end if
    end if






  • Former Member
    Former Member
    Thank you tigu! This answers my question perfectly. I was overthinking and used workflows to trigger VBScript. Using automatic property validation is so much better for my need.