Sequence number generation
The gadget spec URL could not be found



The order ID (E.g. ORD1000001) must be automatically generated whenever a new order is created using the "Create Order" option. In order to generate order ID automatically, the following changes are needed.
  • Maintain the next sequence number in a model that can be accessed from "CustomerOrders" model.
  • Create an action to update the next sequence number.
  • Configure "Create Order" action to fetch the sequence number, update order ID in the "CustomerOrders" model and update the next available sequence number.
Should we create a separate model for maintaining next sequence number or use the system models? What are the available options?

"Company" or "Application" system model could be used for maintaining the sequence number.

The purpose of "Application" system model is to store the application specific configuration details such as authentication, mail configuration, log level etc. This application configuration details can be updated by the admin user in run-time. Since there must be only one instance for this model, only the instance created by the system for this model must be updated; no new instances must be created.

The purpose of "Company" model is to store company specific details.
If more than one company uses the same application (multi-tenant applications), one instance will be created for each company.

Click here to learn more about system models.

"Company" vs "Application"?

Since we are not building a multi-tenant application, the "Company" system model can be used for maintaining the next sequence number. The application will be used only by the company "teeq". Hence, there will be only one instance for "Company".

Company Data Model
  
Open the Company data model. Create a public cell "Next_Sequence_Number".
   
Select the "Next_Sequence_Number" public cell and click on the "DefaultValue" icon.
   
"Default Value" dialog box will be displayed. Enter the default value as "1000000".
   
 If no value is specified for a public cell, which has a default value set, then while creating a new instance, the value for that public cell will be set to the default value.

For example, the value for "Next_Sequence_Number" will be set to "1000000".


Update Sequence Number Action
  
Click on the "Insert Action" icon.
   
"Insert New Action" dialog box will be displayed. Enter "UpdateSeqNum" in the name field.
   



Update sequence number in company model
  
Insert an update command.
   
Click on the properties tab to configure the command parameters .

Param: Next_Sequence_Number
Value: =Next_Sequence_Number+1
   
   


Connect "CustomerOrders" - "Company" model
  
Open "CustomerOrders" data model. Create a public cell "Company_Reference".
   
Write a DGET database function to fetch the user's company from the User model.

=DGET(CreatedBy,User.Company)
   
Did you know?
 Every model is connected to the User model via cells CreatedBy and ModifiedBy. Refer visualization shown at the bottom of this page.

Hence, CreatedBy or ModifiedBy can be used as a reference cell to fetch values from the User model.
  
Establish a formula reference connection. This reference can be used to fetch the next sequence number from the Company model.
   


Visualization - Summary
   
  CustomerOrders - ProductOrders
(One-many, Parent-Child)

Company - CustomerOrders
(One-Many)

Customer - CustomerOrders
(One-Many)
  
What's the next step?

Create "Create Order" action.