How to get the next sequence number using V7 Style coding?

2 minute read time.

Previously here, I discussed “A very basic example of V7 style coding with Representation and Class”.

Because of that I received a question on, how you can get the next sequence number in class code and in this post I like to show you a simple example of that.

Before getting to the point of this blog post,  please review an online help entry titled "Get a sequence number value" which is accessible in Sage X3 online help by searching for the title.



The above online help, is discussing using  NUMERO funprog, from ANM_TOOL script and in below example which is based on ZCLIENT class which was discussed on the first blog I am going to populate a new field with a sequence number.

  1. Open Setup, General Parameters, Sequences number Definition, Structures.
  2. Create a custom sequence number.



  3. Now, I have a field in my ZCLIENTH table that I like it to be populated with the next sequence number.





  4. Open Development, Data and parameters, Classes, Classes.
  5. Select ZCLIENT class.
  6. Add CLIENTSEQ field to the property of the class if you have not already add it. (you can do this by using the column selection action)





  7. Save and validate.
  8. On the general tab, notice the script name for your class.




  9. Open Development, Script Dictionary, Scripts, Script editor.
  10. Enter your class script name.
  11. Add the following code.





    $METHODS
    Case [L]CURPTH
        When ""
       Case [L]ACTION
        When "AINSERT_BEFORE"          : Gosub AINSERT_BEFORE
       Endcase
    Endcase
    Return

    $AINSERT_BEFORE
    Local Char WMESSAGE(250)
    [L]ASTATUS=func ANM_TOOL.NUMERO(this.ACTX,"ZALI","",date$,"",this.CLIENTSEQ,WMESSAGE)
        If [L]ASTATUS>= [V]CST_AERROR
           [L]ASTATUS = fmet this.ASETERROR ("CLIENTSEQ", WMESSAGE, [V]CST_AERROR)
        Endif
    Return

    $PROPERTIES
    Case [L]CURPRO
     
    Endcase
    Return



  12. Open Development, Data and parameters, Classes, Representations.
  13. Select ZCLIENT representation.
  14. Add the new CLIENTSEQ field to the Displayed properties.




  15. Save and Validate.
  16. Now when you launch your representation and create a new record, the ClientSeq field will get populated with the next sequence number.




Conclusion:


You can use NUMERO on ANM_TOOLS to get the next sequence counter.

What is next:

In future blogs I will be talking about how you can manage two tables like a header and line, and REST web service with representations, so stay tune for that.