GenerateCodeNumber

You can use the GenerateCodeNumber function to generate a unique code number for creating new objects.

When to use

You can use this function to:

  • Generate a unique object code before creating a new object.
  • Display a proposed object code to users for confirmation.

When not to use

You cannot use this function:

  • When using CreateObjectUsingCreateRule, as the function generates codes automatically.
  • When manually specifying an object code instead of using automatic code generation.

Syntax

string GenerateCodeNumber(string createRule)

Parameters

Parameter Type Required Description
createRule string Yes The name or code of the create rule associated with the object symbol.

Impact

  • The function reserves or increments sequence numbers in the create rule, depending on the configuration.
  • The function may update create rule counters or sequence generators.

Prerequisites

  • The create rule needs to exist and be properly configured.
  • The maximum code length restrictions may apply based on the object type.
  • The create rule can include only automatic segments such as Prefix, NextKey, Segment, Version, or Ver.Subver.
  • The user input is not supported in the create rule.

Return Value

The application returns a unique code as a String if the operation is successful.

Examples

Example 1
Generate and Save New Formula Code.
string codeNumber = GenerateCodeNumber("EXP FORMULA");
long rc = ObjectSaveAs("FORMULA", "PIZZA SAUCE\\0001", ref codeNumber);
Description
The script generates a new unique formula code using the "EXP FORMULA" create rule, then creates a copy of the existing formula "PIZZA SAUCE\0001" with this new code.