BeforeCreateNewObjectFinalize and External Objects

We have an event handler script that explicitly excludes an externally maintained Project object:

' Get the user name
Dim userAccount
Set userAccount = Vault.UserOperations.GetUserAccount(CurrentUserID)
Dim vloginName
vloginName = userAccount.LoginName

'Get instance of Property values
Dim oPropVals: Set oPropVals = CreateObject("MFilesApi.PropertyValues")
Set oPropVals = Vault.ObjectPropertyOperations.GetProperties(ObjVer)

currentTitle = oPropVals.SearchForProperty(MFBuiltInPropertyDefNameOrTitle).TypedValue.Value

currentClass = oPropVals.SearchForProperty(MFBuiltInPropertyDefClass).TypedValue.DisplayValue


If ( currentClass <> "Project") Then
If ( ( (InStr(1, currentTitle, "!") > 0) _
or (InStr(1, currentTitle, "~") > 0) _
or (InStr(1, currentTitle, "@") > 0) _
or (InStr(1, currentTitle, "#") > 0) _
or (InStr(1, currentTitle, "%") > 0) _
or (InStr(1, currentTitle, "^") > 0) _
or (InStr(1, currentTitle, "&") > 0) _
or (InStr(1, currentTitle, "*") > 0) _
or (InStr(1, currentTitle, "?") > 0) ) _
and (InStr(1, vloginName, "mf_service") = 0) ) _
Then
Err.Raise MFScriptCancel, "Please remove the special characters in " + currentTitle
End If
End If

Yet, full refreshes of the Project object fail to complete.  Watching the refreshing status, I can see that objects are not updated or inserted.

Parents
  • And instead of checking for the presence of special characters and reacting with an error, why don't you just remove them: 

    Replace(currentTitle,"!","")

  • I can try that and see if Refreshes work again.  Thanks.

  • Alas, my Project object refresh still failed to insert new objects and update existing ones when the event handler was active.  Only when I deactivated it did it go through.  Here is the code:

    ' Get the user name
    Dim userAccount
    Set userAccount = Vault.UserOperations.GetUserAccount(CurrentUserID)
    Dim vloginName
    vloginName = userAccount.LoginName

    'Get instance of Property values
    Dim oPropVals: Set oPropVals = CreateObject("MFilesApi.PropertyValues")
    Set oPropVals = Vault.ObjectPropertyOperations.GetProperties(ObjVer)

    Dim currentProperty
    Set currentProperty = oPropVals.SearchForProperty(MFBuiltInPropertyDefNameOrTitle)
    currentTitle = currentProperty.TypedValue.Value

    currentClass = oPropVals.SearchForProperty(MFBuiltInPropertyDefClass).TypedValue.DisplayValue


    If ( currentClass <> "Project") Then

    If ( ( (InStr(1, currentTitle, "!") > 0) _

    or (InStr(1, currentTitle, "~") > 0) _
    or (InStr(1, currentTitle, "$") > 0) _
    or (InStr(1, currentTitle, "@") > 0) _
    or (InStr(1, currentTitle, "#") > 0) _
    or (InStr(1, currentTitle, "%") > 0) _
    or (InStr(1, currentTitle, "^") > 0) _
    or (InStr(1, currentTitle, "&") > 0) _
    or (InStr(1, currentTitle, "*") > 0) _
    or (InStr(1, currentTitle, "?") > 0) ) _
    and (InStr(1, vloginName, "mf_service") = 0) ) _
    Then
    currentTitle = Replace ( _
    Replace ( _
    Replace ( _
    Replace ( _
    Replace ( _
    Replace ( _
    Replace ( _
    Replace ( _
    Replace ( _
    Replace(currentTitle,"`","_") , _
    "~","_") , _
    "@","_") , _
    "#","_") , _
    "$","_" ), _
    "%","_") , _
    "^","_"), _
    "&","_") , _
    "*","_") , _
    "!","_")


    currentProperty.TypedValue.SetValue 1, currentTitle
    Vault.ObjectPropertyOperations.SetProperty ObjVer, currentProperty
    ' Err.Raise MFScriptCancel, "Replacing special character with " + currentTitle


    End If

    End If

Reply
  • Alas, my Project object refresh still failed to insert new objects and update existing ones when the event handler was active.  Only when I deactivated it did it go through.  Here is the code:

    ' Get the user name
    Dim userAccount
    Set userAccount = Vault.UserOperations.GetUserAccount(CurrentUserID)
    Dim vloginName
    vloginName = userAccount.LoginName

    'Get instance of Property values
    Dim oPropVals: Set oPropVals = CreateObject("MFilesApi.PropertyValues")
    Set oPropVals = Vault.ObjectPropertyOperations.GetProperties(ObjVer)

    Dim currentProperty
    Set currentProperty = oPropVals.SearchForProperty(MFBuiltInPropertyDefNameOrTitle)
    currentTitle = currentProperty.TypedValue.Value

    currentClass = oPropVals.SearchForProperty(MFBuiltInPropertyDefClass).TypedValue.DisplayValue


    If ( currentClass <> "Project") Then

    If ( ( (InStr(1, currentTitle, "!") > 0) _

    or (InStr(1, currentTitle, "~") > 0) _
    or (InStr(1, currentTitle, "$") > 0) _
    or (InStr(1, currentTitle, "@") > 0) _
    or (InStr(1, currentTitle, "#") > 0) _
    or (InStr(1, currentTitle, "%") > 0) _
    or (InStr(1, currentTitle, "^") > 0) _
    or (InStr(1, currentTitle, "&") > 0) _
    or (InStr(1, currentTitle, "*") > 0) _
    or (InStr(1, currentTitle, "?") > 0) ) _
    and (InStr(1, vloginName, "mf_service") = 0) ) _
    Then
    currentTitle = Replace ( _
    Replace ( _
    Replace ( _
    Replace ( _
    Replace ( _
    Replace ( _
    Replace ( _
    Replace ( _
    Replace ( _
    Replace(currentTitle,"`","_") , _
    "~","_") , _
    "@","_") , _
    "#","_") , _
    "$","_" ), _
    "%","_") , _
    "^","_"), _
    "&","_") , _
    "*","_") , _
    "!","_")


    currentProperty.TypedValue.SetValue 1, currentTitle
    Vault.ObjectPropertyOperations.SetProperty ObjVer, currentProperty
    ' Err.Raise MFScriptCancel, "Replacing special character with " + currentTitle


    End If

    End If

Children
  • I would shorten it to

    'Get instance of Property values
    Dim oPropVals: Set oPropVals = CreateObject("MFilesApi.PropertyValues")
    Set oPropVals = Vault.ObjectPropertyOperations.GetProperties(ObjVer)
    
    Dim currentProperty
    Set currentProperty = oPropVals.SearchForProperty(MFBuiltInPropertyDefNameOrTitle)
    currentTitle = currentProperty.TypedValue.Value
    
    currentClass = oPropVals.SearchForProperty(MFBuiltInPropertyDefClass).TypedValue.DisplayValue
    
    If ( currentClass <> "Project") Then
    
    	currentTitle = Replace(currentTitle,"`","_")
    	currentTitle = Replace(currentTitle,"~","_")
    	currentTitle = Replace(currentTitle,"@","_")
    	currentTitle = Replace(currentTitle,"#","_")
    	currentTitle = Replace(currentTitle,"$","_")
    	currentTitle = Replace(currentTitle,"%","_")
    	currentTitle = Replace(currentTitle,"^","_")
    	currentTitle = Replace(currentTitle,"&","_")
    	currentTitle = Replace(currentTitle,"*","_")
    	currentTitle = Replace(currentTitle,"!","_")
    
    	currentProperty.TypedValue.SetValue 1, currentTitle
    	Vault.ObjectPropertyOperations.SetProperty ObjVer, currentProperty
    	' Err.Raise MFScriptCancel, "Replacing special character with " + currentTitle
    
    End If

    taking the current user is redundant because it is performed by the system here

  • As a general comment, you should avoid using display names in your logic as the script will break if someone goes and renames the class. The best practice is to find the structure elements by their aliases, which should not change once set.

  • Thanks.  Good to know that it's the system itself that is finalizing the creation of the document.

  • Once I replaced my code with this code, the Project object refreshes worked again.  Not sure why yet.

    Thanks for everyone's input.Grinning