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

OnDiscarded table script

I'm trying to update affiliations when a person is added/removed from PersonInOrg.  The update is working correctly using a process with an Insert event.  However, the delete event does not work - I believe it is firing the delete event, but it seems to update affiliations using the data before the deletion occurs.  So now I'm trying to use an OnDiscarded table script in the PersonInOrg table, but it doesn't seem to be working either.  I'm wondering if the user info is already gone by the time the OnDiscarded script runs?   

Below is the script I'm using.  Any suggestions?


Dim affiliation As String = ""
Dim scopedAffiliation As String = ""
Dim f As ISqlFormatter = Session.SqlFormatter
Dim eLDAPAccountEnt As IEntity

affiliation = VI_Build_Affiliations( $UID_Person$, "CCC_scopedAffiliation", "0")
scopedAffiliation = VI_Build_Affiliations( $UID_Person$, "CCC_scopedAffiliation", "1")

If Not String.IsNullOrEmpty($UID_Person$) Then
Dim qPerson = Query.From ("LDAPAccount") _
.Where(f.AndRelation(f.UidComparison("UID_Person", $UID_Person$), _
"UID_TSBAccountDef In (SELECT UID_TSBAccountDef FROM LDAPAccount INNER JOIN TSBAccountDef ON LDAPAccount.UID_TSBAccountDef = TSBAccountDef.UID_TSBAccountDef WHERE TSBAccountDef.Ident_TSBAccountDef = N'Enterprise Directory Account')")) _
.Select ("UID_LDAPAccount", "CCC_affiliation", "CCC_scopedAffiliation")

eLDAPAccountEnt = Session.Source.GetCollection(qPerson).FirstOrDefault

If Not eLDAPAccountEnt Is Nothing Then
If Not affiliation = eLDAPAccountEnt.GetValue("CCC_affiliation").String Then eLDAPAccountEnt.PutValue("CCC_affiliation", affiliation)
If Not scopedAffiliation = eLDAPAccountEnt.GetValue("CCC_scopedAffiliation").String Then eLDAPAccountEnt.PutValue("CCC_scopedAffiliation", scopedAffiliation)
eLDAPAccountEnt.Save(Session)
End If
End If