DialogNextId does not increment correctly

Hello,

We implemented a script that generates a counter that incrementseach time people are created, the script calls the "DialogNextID" table, here is the body of the script:

Public Function CCC_GetNextIGAID As String
'Dim strIGAID As String = String.Empty
Dim Counter As String = "IGA_ID_COUNTER"

Dim MaxLen As Integer = 7
Dim strIGAID As String = String.Empty
Dim nextID As ISingleDbObject

nextID = Connection.CreateSingle ("DialogNextID")
nextID ("Ident_DialogNextID"). NewValue = Counter
strIGAID = String.Format ("{0}", VID_FillNumber (CLng (nextID.Custom.CallMethod ("GetNextID")), MaxLen))

Return strIGAID

'Dim nextID As Integer = CInt (globalID.CallFunction ("GetNextID"))


'strIGAID = String.Format ("{0}", (nextID), MaxLen)
Return strIGAID

End Function

The problem when I call the script in a template, the counter increments by 3 each time.
Would you be why the increment is not done by 1?

Thank's for your reply.

Monsif CHOUAY.

  • First of all, I would write the function for current versions of One IM in a way that it is utilizing the entity layer.

    Public Function CCC_GetNextIGAID() As String
        ' Get or create IGA_ID_COUNTER 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""IGA_ID_COUNTER", ValType.String)) _
                                      .GetQuery, EntityLoadType.Interactive, globalID) _
        Then
            globalID = Session.Source.CreateNew("DialogNextID",EntityCreationType.Interactive)
            globalID.PutValue("Ident_DialogNextID""IGA_ID_COUNTER")
                      globalID.Save(Session)
        End If

        
        Dim MaxLen As Integer = 7
        Dim nextID As Integer = CInt(globalID.CallFunction("GetNextID"))

        Dim result As String = nextID.ToString.PadLeft(MaxLen"0"c)

        Return result
    End Function


    Secondly, be aware that your template is potentially executed more than once depending on our column dependencies and change order. If you want to ensure that the value is calculated once, than move your template code to the OnSaving Script of the table.

  • Thank's Markus for your reply.

    Calling the script from the table's OnSaving Script doesn' work:

    I added "CustomProperty01 = CCC_GetNextIGAID()" but it doesn't put the value in the CustomProperty01.

    Thank's in advance for your reply.

  • The syntax for the OnSaving script would be:

    Base.PutValue("CustomProperty01",CCC_GetNextIGAID())

    Did you compile the database after changing the OnSaving-script?

  • Tank you Markus, 

    It works well.

    Have a good day.