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

Method GetNextID for DialogNextID not working anymore?

Hi people,

I've recently tried to call the method "GetNextID" on a DialogNextID object using a script. It seems that calling this method does not affect the loaded DialogNextID object. I was wondering if anyone else ran into this problem in 8.0.1.

My script below tries to set a DialogNextID to a specific NextNumber throught the object layer (I am ware the same can be achieved through SQL, but why should the callmethod not work in this instance?)

Has anyone else tried to use the NextID method already? Thanks for your feedback!

Public Sub CCC_Set_StartingCount_GlobalID(ByVal globalIDCount As Integer, Optional ByVal resetCounter As Boolean = False)

' Get or create GlobalID Counter

Dim f As ISqlFormatter = Session.SqlFormatter

Dim globalID As IEntity = Nothing

If Not Session.Source.TryGet(Query.From("DialogNextID") _

.Where(f.Comparison("Ident_DialogNextID", "GlobalID", ValType.String)) _

.GetQuery, globalID) _

Then

globalID = Session.Source.CreateNew("DialogNextID")

globalID.PutValue("Ident_DialogNextID", "GlobalID")

globalID.Save(Session)

End If

If Not resetCounter Then

' Set GlobalID counter to appropriate count

If CInt(globalID.GetValue("NextNumber")) < globalIDCount Then

While Not CInt(globalID.GetValue("NextNumber")) = globalIDCount

Debug.WriteLine(CStr(globalID.GetValue("NextNumber")))

End While

End If

Else

' Reset GlobalID Counter

CCC_Run_SQLWithResult(String.Format("UPDATE DialogNextID SET NextNumber = 0 WHERE {0}",

f.UidComparison("UID_DialogNextID", globalID.GetValue("UID_DialogNextID"))))

End If

End Sub

Parents
  • Resetting DialogNextID.NextNumber using the object layer and GetNextID is a bad idea and should not be considered. Please remember that any execution of GetNextID issues a write to the database. So when you are iterating the counter by adding 1 at a time, this puts an unnecessary load onto the database server. 

    If you need to constantly change your NextNumber then it is better to delete the entry in DialogNextID and create a fresh one correctly initialized with your new number.

    In regards to your claim that calling GetNextID does not change the already loaded object, this is true because it wouldn't make sense to do so in a multi-user environment. At the time the local entity would have been updated, another user (or thread, job service, anything) could have called the same method and your local entity would have been invalid again.

    By the way, the intended use of DialogNextID is not to read the value from NextNumber but to use the function GetNextID to fetch the next number directly and immediately. A requirement to be able to make that function call, is to load the Entity with the EntityLoadType.Interactive (The same requirement applies to a method call of GetNextID).

    Sample: Fetch the next value from DialogNextID

    Dim globalID As IEntity = Nothing
    Dim nextID As Integer
    
    If Session.Source.TryGet(Query.From("DialogNextID"). _
                         Where(f.Comparison("Ident_DialogNextID", "GlobalID", ValType.String)). _
                         GetQuery, EntityLoadType.Interactive, globalID) Then
        nextID = CInt(globalID.CallFunction("GetNextID"))
    End If
    

    You can subsequently call the function and the value will always return the next valid value, regardless what the current value of the NextNumber property.

    HtH

  • Hi Markus,

    thank you very much for your in-depth reply, I found your explanation very useful and comprehensible. I wasn't aware of the EntityLoadType option until now.

    I agree that resetting a DialogNextID, or otherwise massively raising the count of a DialogNextID through the object layer is a bad idea for the reasons you have mentioned. The script that I have posted was not intended for production purposes but rather to figure out why the counter was not being raised.

    Once again Thank you very much for your help!

Reply
  • Hi Markus,

    thank you very much for your in-depth reply, I found your explanation very useful and comprehensible. I wasn't aware of the EntityLoadType option until now.

    I agree that resetting a DialogNextID, or otherwise massively raising the count of a DialogNextID through the object layer is a bad idea for the reasons you have mentioned. The script that I have posted was not intended for production purposes but rather to figure out why the counter was not being raised.

    Once again Thank you very much for your help!

Children
No Data