Custom Counter Fields

You can add an auto-increment (also known as a "counter") field to any form. Just add the field to the form, with the data type set to "Counter", and set its Calculated setting to Yes. Now whenever that record is created, it will be assigned a unique number that increments automatically for each record added.

Keep in mind, though, that the number may not always be consecutive. If a record is deleted, for example, the number wont be re-used. Also if a transaction is aborted, through an error for example, while another record is being created, then you may find that numbers are skipped. It will, however, always be unique across all those forms in the system.

A quick way to look-up a record from a number is by either clicking the "Search" text in the top right corner of your app (if Search is enabled). In there you'll see an area where you can select a form type and then enter in a record number. Once you enter the number and press ENTER, it will take you straight to the given record.

Sometimes you may not want a simple number, you may want it prefixed with something that helps you identify what it is. For example a quotation may be prefixed with "Q" so you can have a unique code for your quotation such as Q1234. You can control the formatting of the counter field like this by using the Format Code setting of the field. This lets you override how the data is presented to the user. In that setting you can use DbfScript to format the value, for example:

 ="Q" + #value

...would show the value prefixed with a Q.

If you did this for several forms, you may want to add a global action that can be used to easily look-up such forms from a single entered code.

To do this, add a global action called Lookup Form.

1. Go to the Application record, in Designer.
2. Click the hamburger icon and select "Actions", then click "+" to add a new action.
3. Give it a name, "Lookup Form"
4. In the Script section put something like this:

if str:StartsWith(#input/Code, "Q") then
     var #frm = load(all &root/SomeForm[SomeCounter=Substring(#input/Code, 1, 1000)] below &root)
     if Exists(#frm) then
         redirect ViewLink(GetPath(#frm))
     end if
 end if
 if NotExists(#frm) then
     error "Sorry, no form matching that code could be found."
 end if

In that script, change SomeForm to be the name of your form, and SomeCounter to be the name of your counter field.

5. Add a field in Script Input Fields called "Code", with a type of Number (Integer).

Now publish your application.

Once published, go to What's Next / Lookup Form, and enter in the code of your form, and it should then take you directly to that form.

If you have multiple forms with different codes, then just repeat the section that checks if it starts with "Q" for each type of form you have. Then, for example, if you entered Q1234 it will take you to the quotation numbered Q1234, but if you entered in PR5432 it will take you to the purchase request with the number 5432.


Next Topic:
v4.2.0.956 (beta)
Up Since 2/29/2024 12:02:23 AM