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

  • Thanks. I was working on being able to compile in System Debugger, but I'm getting lots of the 'Imports statements must precede any declarations' errors in CustomerScripts. What's the proper way to handle those? I'm guessing I probably shouldn't be moving all Imports statements to the top?
  • Check that all your IMPORTS in your custom scripts are wrapped in the proper SCRIPTDEBUGGER condition like the following sample.

    #If Not SCRIPTDEBUGGER Then
    	IMPORTS MyNamespace.Sample
    #End If

  • Great - now I just have 'Type PhoneNumber is not defined' and 'Type DefenderClient is not defined' errors left in the ProductScripts. Is PhoneNumberKey the correct type? I didn't get any suggested alternative types for DefenderClient.

    Is there documentation for this sort of thing anywhere?
  • I found the missing QER.DefenderClient dll on another machine, just not sure why it's not on this one (same version). Not finding a dll for PhoneNumber.
  • The type PhoneNumber is also defined in the QER.DefenderClient.dll. The complete namespace would be QER.DefenderClient.PhoneNumber but there is an IMPORTS statement that shortens this to PhoneNumber.

    In regards to the documentation, as these are basic Visual Basic (.NET) solution behaviors this is documented as such in the documentation from Microsoft or in several other how-to documents you will find in the Internet.

    Did you know that we have a whole video series on Youtube around Scripting? It is might worth a subscription. https://www.youtube.com/watch?v=UjZdOW8pbM4&list=PL242czeZwlAk0T2AcqpSFtBOXQfkP9f5J 

  • I will definitely take advantage of the scripting videos - thanks! I was able to compile finally and now have access to the SystemDebugger. The PersonInOrg filter doesn't seem to work like the Person filter, though. I've tried filtering by name, UID_Person, and role, but none of them are finding any results.
  • Below is the stack trace. I see a reference to VI.DB.Entities.ReadOnlyEntity. Can IEntity not be used for writing, or am I using the wrong method to save?

    at DynScripts.Table_zVO4zqrYf4KkpG0W0z6GC2mnA.PersonInOrg_OnSaving()
    at VI.Base.SyncActions.Do(Func`1 action)
    at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
    at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
    ---- Start of Inner Exception ----
    at VI.DB.Entities.Entity.<SaveAsync>d__76.MoveNext()
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    --- End of stack trace from previous location where exception was thrown ---
    at VI.DB.Entities.EventUnitOfWork.<PutAsync>d__2.MoveNext()
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    --- End of stack trace from previous location where exception was thrown ---
    at VI.DB.Entities.UnitOfWorkImpl.<PutAsync>d__37.MoveNext()
    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
    --- End of stack trace from previous location where exception was thrown ---
    at VI.DB.Entities.DbEntitySink.<PutAsync>d__14.MoveNext()
    at VI.DB.Entities.ReadOnlyEntity.BeginTransaction()
  • Bingo. Now after looking into your code again, I found the solution.

    You are creating the IEntity directly out of the collection using the method FirstOrDefault.

    The thing is, that your collection is loaded using the default collection load type and this leads to iEntity objects that are read-only.

    The easiest way to create a writeable object for your eLDAPAccountEnt is to add the following line after you have created the entity.

    eLDAPAccountEnt.Create(Session)

    Another option would be to load the collection with the EntityCollectionLoadType.Bulk.

    eLDAPAccountEnt = Session.Source.GetCollection(qPerson, EntityCollectionLoadType.Bulk).FirstOrDefault()

  • Thank you - that's a huge help! It's still not updating the LDAP table correctly, but that took care of my error anyway!