Understanding Generators

Your application may need a unique identifier, such as a quote number or product SKU, to make it easy for your customers to find specific transactions or resources. Because Snap is a language that can process multiple transactions from many people at once, generators and GUIDs (which are calculated at the server) are the only reliable way to create a sequential number or unique identifier. Epicor CPQ has two ways to generate these identifiers: a generator resource and the GUID Snap block.

Understanding Two Ways to Generate Unique Identifiers

Start with a Generator. Move up to a GUID when necessary.
For customer-facing identifiers that people will use to identify quotes or other transactions, we suggest you use a sequential ID from a generator, as shown below. For identifiers used internally that people won't often see or use for lookups, use a GUID. A full 32-character GUID is long and can look confusing to people, but are almost guaranteed to never clash with another GUID now or in the future. Learn more about GUIDs.

The generator resource and the GUID Snap block have different benefits.

  Generator Resource GUID Snap Block
Examples Q1234, 35, 36... (for quotes)
C-4000, 01, 02... (for configured products)

f81d4fae-7dec-11d0-a765-00a0c91e6bf6
30dd879c-ee2f-11db-8314-0800200c9a66

Length from 1 to 5 digits, plus your custom prefix/suffix chars up to 32 characters
Customize

Yes

No

Reliably Unique Not across environments (see below) Yes, when 32 characters long.
Sequential Yes No
Best used for

Short customer-facing IDs where ease of use is more important.

IDs that are incremental.

Long internal-facing IDs where global uniqueness is more important.

IDs that need not be incremental.

  • Generators provide unique sequential numbering for many different uses, including Quote serial numbers, part numbers, etc. 
  • The GUID Snap Block provides a more unique identifier across all environments, but it is somewhat unwieldy for users (takes up more space when displayed and more difficult to type for lookups). Learn more about GUIDs.

Generator Resource Properties

You can create multiple generators. In the admin menu, select resources > generators and set the properties of the generator:

Property Description
Name A name for the generator to easily identify it in rules.
Seed The number to start with. By default this is 1.
Increment

How to increment the number.

  • If the increment is 1, then the sequence seeded with 1 will be 1, 2, 3...
  • If the increment is 5, the sequence will be 1, 6, 11, 16...

Generators are unique within an environment, not across the entire org.
For example, if you have designed a "quote number" generator in DEV seeded at 101, and you generate 9 quotes in DEV, then the generator in DEV will produce 110 at its next call.  However, when that generator is deployed to TEST or PROD, it will have the same starting seed of 101 and will offer that number when first called.  This is intentional: you can use a generator many times in one environment during development or testing, and it will not cause a jump in the unique sequential numbering used in another environment, like production.

Follow the example below to see how you can control this uniqueness across your orgs.

Generator Resource Examples

For example, consider if a new generator were created under Admin > Resources > Generators called "Quote ID Generator" with a seed of 100 and increment of 1. Then this basic quote number function could be written:

This naive code generates these quote numbers in the 3 environments.

dev Q-101, Q-102, Q-103...
test Q-101, Q-102, Q-103...
prod Q-101, Q-102, Q-103...


What if you want a unique number across all environments? For example, how can you ensure a quote PDF from your Test environment is not confused with an actual Production environment quote? Simply add more logic to your quote number.

A better function includes the environment as a suffix, if it is not a production quote:

This better code generates these less-confusing quote numbers across the three environments.

dev Q-101-DEV, Q-102-DEV, Q-103-DEV...
test Q-101-TEST, Q-102-TEST, Q-103-TEST...
prod Q-101, Q-102, Q-103...

GUID Snap Block Example

While the Generator is customizable, the GUID is not. Creating a GUID is simple. In a Snap workspace, find the "GUID" block in the toolbox. Usually, the results would be written into a configurator field, or a local variable.

For database inserts, you would usually insert the resulting GUID into the "GUID" column of a custom table.

Was this article helpful?