Creating serialized forms for Web applications in Notes is a simple three step process. The requirements are for a form showing the next number unless the form was previously saved, in which case it keeps the serial number it was assigned originally.
Create the Form, View, and Agent below. The computed field called "reqid" holds the serial number. The serial number is not changed if the form is edited. Only new submittals get the next serial number. You may choose to start with 1 or you may start with a larger initial number as shown: 1000. The first record will get 1000, the next 1001, ... etc.
There are two fields on the form: a computed for display (reqid_1) field will show up only when the document is "new", displaying the "next" serial number. If you don't save the document that serial number is not used.
If you edit a previously saved document, the computed field (reqid) will show up.
If there are several people using the form, the first person to save their document will get the next number, so the computed for display field may not be completely accurate in a busy environment.
You may wish to simplify by eliminating the reqid_1 field and both "hide if" formulas. Then the serial field (reqid) will simply be blank until you save the document to "set" its serial number.
Code
1. Form (2 fields and an agent):
Computed Field: reqid
Type: numeric, 0 digits after decimal
Hidden if: @IsNewDoc (optional see text above)
Computed for Display field: reqid_1 (field is optional; see text above)
Type: numeric, 0 digits after decimal
Hidden if: !@IsNewDoc
Formula:
@If(reqid="";@If(@Subset(@DbColumn("":"nocache";"";"(num)";1);1)="";1000;
@Subset(@DbColumn("":"nocache";"";"(num)";1);1)+1);reqid)
WebQuerySave Agent:
@Command([ToolsRunMacro]; "setid")
2. View (one column)
Private View: (num)
First Column: reqid
Column data: numeric, 0 digits after decimal
Properties: Sorted, descending order
3. Shared Agent:
name: "setid"
When: Manually from Actions Menu
Which: Run once (@Commands may be used)
Agent Code:
FIELD reqid := reqid;
id := @If(reqid="";@If(@Subset(@DbColumn("":"nocache";"";"(num)";1);1)="";1000;
@Subset(@DbColumn("":"nocache";"";"(num)";1);1)+1);reqid);
@SetField("reqid";id)