Object Script Example
Writers, this example is lost here, perhaps move it to a better place during re-organization
In this example, we need to create values for a Document Number field, based on sequential IDs where the leading letters represent a particular document type. The types must be mixed without breaking the sequence. For example, as objects of different document types are created, the Document Number field might contain values such as the following:
- AAA0001
- AAA0002
- BBBG001
- AAA003
The Auto-Number field cannot be used because more than one sequence is involved. Instead, to fulfill this requirement, try the following solution:
- Create a picklist field,
doc_prefix
, with values AAA, BBB etc. - Create an integer field,
seq_num
, but do not add this field to any page or view. -
Use the following Object Script methods in an After Create trigger to populate the Document Number field (read-only on pages):
// Find next sequential number var nextNum = rbv_api.selectNumber("select MAX(seq_num) from documents where doc_prefix='{!doc_prefix#value}'") + 1; // Format document number var nextStr = nextNum.toString(); while (nextStr.length < 4) nextStr = '0'+nextStr; var docNumber = '{!doc_prefix#value}'+nextStr; // Record document number and sequential number rbv_api.setFieldValue("documents", {!id}, "name", docNumber); rbv_api.setFieldValue("documents", {!id}, "seq_num", nextNum);