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

SearchForPropertyEx doesn't actually return a NULL?

Dim propEffDate
Dim effDatePropDef

effDatePropDef = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("M-Files.Property.EffectiveDate")

'Does the Object already have the Effective Date Property?
set propEffDate = PropertyValues.SearchForPropertyEx(effDatePropDef, true)

IF IsNULL(propEffDate) THEN
  Err.Raise 2, "NULL"
END IF
IF IsEmpty(propEffDate) THEN
  Err.Raise 3, "Empty"
END IF
IF IsObject(proEffDate) THEN
  IF proEffDate IS NOTHING THEN
    Err.Raise 5, "Nothing"
  END IF
  Err.Raise 4, "Object"
END IF

I am running this script in a State Action where I want to set the value of a Property. The Property may or may not be attached to the object so I am searching for the PropertyDef by Alias, then using this value to search the PropertyValues collection to see if the Property is included. However this Code triggers NONE of the Err.Raise (which I am just using to diagnose the behavior). I was expecting the IsNULL check to be true since that is what the documentation implies is the purpose of the SearchForPropertyEx call. But whatever is returned is neither NULL nor an Object so the code happily bypasses all these IF statements. What should I be expecting here.

Also, is there any way to perform logging from within a script? It is extremely difficult to observe what is happening.

-Jason

Parents
  • If all you want to do is validate if the property is on the PropertyValues, you can also do the following 

     

    ' if the property is not on the metadata card , it returns a -1 for the index. 
    IF PropertyValues.IndexOf(propEffDate) > -1 Then
     ' put code here
    END IF

    As for additional logging, the main way to troubleshoot is to use the Err.Raise like you are doing. On rare occasions for bigger scripts I also sometimes add an "on error resume next" on the top of my script to let it run through all the if statements and have it append my messages to a variable which I then output to a multi text value property so I can see everything at once. 

  • I'm not really sure why the SearchForPropertyEx doesn't behave as documented. I switched to this method and was able to achieve the goal. Below is the complete working script for others to see.

    Dim propEffDate
    Dim effDatePropDef
    
    effDatePropDef = Vault.PropertyDefOperations.GetPropertyDefIDByAlias("M-Files.Property.EffectiveDate")
    
    'Does the Object already have the Effective Date Property?
    set propEffDate = PropertyValues.SearchForPropertyEx(effDatePropDef, true)
    
    If PropertyValues.IndexOf(effDatePropDef) < 0 Then
      'Property isn't already in the collection
      'create the property object
      set propEffDate = CreateObject("MFilesAPI.PropertyValue")
      propEffDate.PropertyDef = effDatePropDef 
    End If
    
    'Now change the Date to the current date and save it
    propEffDate.TypedValue.SetValue MFilesAPI.MFDataType.MFDatatypeDate, Date
    Vault.ObjectPropertyOperations.SetProperty ObjVer, propEffDate
    

  • Hi,

    Not sure what's going on in your script, but "Is Nothing" should have caught it if it truly does not exist in the collection:

    Option Explicit
    
    Dim propEffDate
    set propEffDate = PropertyValues.SearchForPropertyEx(1096, true)
    
    Err.Raise MFScriptCancel, IsObject(propEffDate) & ", " & IsNull(propEffDate) & ", " & (propEffDate Is Nothing)

    Regards,

    Craig.

  • I'll have to test the scenario with Option Explicit enabled, that may be required for the behavior to work as intended?

  • Option Explicit just forced you to declare variables. It shouldn't change any other behaviour. 

Reply Children
No Data