The M-Files Community will be updated on Tuesday, April 2, 2024 at 10:00 AM EST / 2:00 PM GMT and the update is expected to last for several hours. The site will be unavailable during this time.

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

2 If VBScript

I need some help with my script.

My script should be checking 2 properties

If PropVal is not "Self" the other value (Contact) should be Null or empty.

Option Explicit

Dim szPropertyName, szPropVal
szPropertyName = PropertyDef.Name
szPropVal = PropertyValue.GetValueAsUnlocalizedText


If not szPropVal = "Self" then
Dim szContactVal : szContactVal = PropertyValues.SearchForProperty(1257).TypedValue.DisplayValue

If szContactVal <> "Self" Then
Err.Raise MFScriptCancel, "ContactVal should be empty."

End if
End if

Thank you.

Parents
  • Here is the solution I came up with according to your requirements. Place this script in the Validation section of the Contact property definition.

    Option Explicit
    Const pd_Self = 1150 'ID of property def to evaluate the text value. Locate this from your vault

    ' PropertyValues is not exposed within validation scripts so we create it
    Dim oPropVals: Set oPropVals = CreateObject("MFilesApi.PropertyValues")
    Set oPropVals = Vault.ObjectPropertyOperations.GetProperties(ObjVer)

    'The property definition value to inspect.
    Dim selfvalue : selfvalue = oPropVals.SearchForProperty(pd_Self).TypedValue.Value

    'PropertyValue represents the property definition where the validation script is running. 
    'Check if there is a value and compare if the other contains "Self"
    If Not PropertyValue.TypedValue.IsNull() AND selfvalue = "Self" Then
    Err.Raise MFScriptCancel, "The Contact property should be empty"
    End IF

    A few notes about this solution to be aware of:

    1. Hardcoding text values leave a bit of room for error. If the user types "self" or " self" or "self " the validation will not occur. To secure this for future logical errors, I would add a boolean property definition and validate according to that value. 

    2. I would also suggest to use Aliases when scripting. This gives your scripts scalability if you need to use it within another vault, such as from Dev to Prod. 

    Let me know if this script works for you by marking it as an answer. 

    Happy Scripting,

    -Sean

Reply
  • Here is the solution I came up with according to your requirements. Place this script in the Validation section of the Contact property definition.

    Option Explicit
    Const pd_Self = 1150 'ID of property def to evaluate the text value. Locate this from your vault

    ' PropertyValues is not exposed within validation scripts so we create it
    Dim oPropVals: Set oPropVals = CreateObject("MFilesApi.PropertyValues")
    Set oPropVals = Vault.ObjectPropertyOperations.GetProperties(ObjVer)

    'The property definition value to inspect.
    Dim selfvalue : selfvalue = oPropVals.SearchForProperty(pd_Self).TypedValue.Value

    'PropertyValue represents the property definition where the validation script is running. 
    'Check if there is a value and compare if the other contains "Self"
    If Not PropertyValue.TypedValue.IsNull() AND selfvalue = "Self" Then
    Err.Raise MFScriptCancel, "The Contact property should be empty"
    End IF

    A few notes about this solution to be aware of:

    1. Hardcoding text values leave a bit of room for error. If the user types "self" or " self" or "self " the validation will not occur. To secure this for future logical errors, I would add a boolean property definition and validate according to that value. 

    2. I would also suggest to use Aliases when scripting. This gives your scripts scalability if you need to use it within another vault, such as from Dev to Prod. 

    Let me know if this script works for you by marking it as an answer. 

    Happy Scripting,

    -Sean

Children
No Data