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

v6 Attribute isMailObject in v7 missing

Hello

Earlier in v7 we have always used the attribute isMailObject  to determine if the ADSAccount has a mailbox.

Whenever we used this %isMailObject% in another column in the template code, the values has been recalculated on change (adding or removing a mailbox).

We can not use the code $FK(UID_EX0MailBox).IsLocked$) because the UID_ADSAccount is referenced on the EX0MailBox object.

Is there another $-Statement that we can use to involve a attribute form the mailbox of the user?

In v7 we use a code like this for e.g. in UserPrincipalName:

...
Dim IsMailObject As Boolean = False
Dim f As ISqlFormatter = Session.SqlFormatter
Dim qMailboxofADSAccountWhere As String = f.Comparison("UID_ADSAccount", $UID_ADSAccount$, ValType.String, CompareOperator.Equal)
IsMailObject = Connection.Exists("EX0MailBox",qMailboxofADSAccountWhere)
If IsMailObject Then
   Dim sUIDEX0MailUser As String = Session.Source.GetSingleValue(Of String)("EX0MailBox", "UID_EX0MailBox", qMailboxofADSAccountWhere)
   Dim oEX0MailBox As ISingleDbObject = Connection.CreateSingle("EX0MailBox", sUIDEX0MailUser)
   If ( CInt(oEX0MailBox.GetValue("IsLocked")) = 0 ) Then
   Value = $Mail$
End If
...

The code will not be recalculated if a mailbox is added later on, or id the mailbox is getting disabled deleted.

Is there any other possibility to trigger a calculation of a template on ADSAccount when a Mailbox is beeng created or disabled, other then to enhance the processes with executetemplantes()

Regards, René

Parents
  • You can trigger the ExecuteTemplate method from the OnSaved script at the exchange mailbox object.

    The only suggestion I would make, but it depends on your full use case, is to use connection variables to pass the status of the IsLocked flag from the mailbox to the AD user for template generation. This would avoid unnecessary database roundtrips.

    Sample code for the OnSaved script would look like the following.

    Dim fk as IEntityForeignKey = Entity.GetFk(Session,"UID_ADSAccount")
    ' The Mailbox has to be linked to an AD User
    If Not fk.IsEmpty Then
    	
    	' Create ADS user entity from fk
    	Dim eADSAccount as IEntity = fk.GetParent(EntityLoadType.Default)
    		
    	' Set session variable for evaluation in Template on ADSAccount.UserPrincipialName
    	Session.Variables.Put("IsLocked", $IsLocked:Bool$)
    	
    	' Execute templates on linke ADSAccount.UserPrincipalName
    	eADSAccount.ExecuteTemplate(Session,"UserPrincipalName")
    	eADSAccount.Save(Session)
    	
    	' Set session variable for evaluation in Template on ADSAccount.UserPrincipialName
    	Session.Variables.Remove("IsLocked")
    	
    End If

    In your template, you can rewrite your code to

    If Session.Variables.Contains("IsLocked") Then
    	If (NOT CBool(Session.Variables("IsLocked"))) Then
    		Value = $Mail$
    	End If 
    End If

  • Thank you Markus, it worked for me with the approach on the OnSaved Script. But the ADAccount was not updated, so I have added save().

    I also have seen also that other Attributes are also based on the mailbox, so I will calculate all templates...

    My Script in OnSaved hook looks now like:

    Dim fk as IEntityForeignKey = Entity.GetFk(Session,"UID_ADSAccount")

    If Not fk.IsEmpty Then

    Dim eADSAccount as IEntity = fk.GetParent(EntityLoadType.Default)

    eADSAccount.ExecuteTemplates(Session)

    eADSAccount.Save(Session)

    End If

Reply
  • Thank you Markus, it worked for me with the approach on the OnSaved Script. But the ADAccount was not updated, so I have added save().

    I also have seen also that other Attributes are also based on the mailbox, so I will calculate all templates...

    My Script in OnSaved hook looks now like:

    Dim fk as IEntityForeignKey = Entity.GetFk(Session,"UID_ADSAccount")

    If Not fk.IsEmpty Then

    Dim eADSAccount as IEntity = fk.GetParent(EntityLoadType.Default)

    eADSAccount.ExecuteTemplates(Session)

    eADSAccount.Save(Session)

    End If

Children