Adding an Auto Sequential Field to your Maintenance Application
There will be many times when, on any data entry screen, you will want your key field to automatically query the database to see what the last number being used was and increase that by one. Using an Auto Sequential field will eliminate your end users from having to select their own key field, and it will also eliminate the need for you to create an external object that would accomplish this.
In the documentation below, we will create an Auto Sequence field for our New Customer Data Entry screen.
Select the appropriate file and fields. In our case we will select Customer Number, Name, Address, and Phone. We will also sequence by Customer Number.
Now that our fields are selected, click “Field Settings” and select the Customer Number field. In the “Field Description” add the text
*AUTOSEQ can replace or be added to the end of the current field description.
Note: Since this field will be written to the database, the “Field Type” must be set to “Update”. In addition, this field must be a numeric sequence key to utilize the auto-sequence functionality.
Click “Accept”. Build/Compile your application.
At run time, we are shown this screen:
The last record in the file for Customer Number was 102061, so our application received the next one available 102062.
A common question — How can I remove the
*AUTOSEQ text? Will this break my application?
You could remove the text via m-Painter, however wouldn’t it make more sense to hide the entire row from view? More often than not, if you do not wish your end user to type in their own key field, you probably do not want them to see it in general. The below process will explain how to hide the row.
- Open m-Painter for your application.
- Right-click on the row you wish to hide, and click “Hide row”.
While you do not see the row hidden, at run time it will not be visible. After saving the application, my screen now shows:
While we cannot see the Auto Sequenced number, it is still within the HTML and ready to be submitted to the database as soon as the user clicks the “Accept” button.