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.
- Open Setup, General Parameters, Sequences number Definition, Structures.
- Create a custom sequence number.
- Now, I have a field in my ZCLIENTH table that I like it to be populated with the next sequence number.
- Open Development, Data and parameters, Classes, Classes.
- Select ZCLIENT class.
- 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)
- Save and validate.
- On the general tab, notice the script name for your class.
- Open Development, Script Dictionary, Scripts, Script editor.
- Enter your class script name.
- 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 - Open Development, Data and parameters, Classes, Representations.
- Select ZCLIENT representation.
- Add the new CLIENTSEQ field to the Displayed properties.
- Save and Validate.
- 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.