Tip #354: No code contextual sequential auto-number

When you add a child entity, it is best practice to populate the name field, but sometimes it can be difficult to come up with a name that makes sense. Say you have an entity that is the child of an account/company record. If you leave the name field blank, if any record looks up to that record, the lookup field will be blank. Plus, say you want to ask the account manager about the record, without a distinct name, it will be difficult to let them know to which record you are referring (sure you can email a link, but follow along).

One approach is to auto number the records with the name of the parent to provide a distinct record name (Acme-1, Acme-2, Acme-2). However, there is no standard way to auto-number records. Sure you could write a plugin, but if you don’t have those skills or you don’t want to take the time, there are additional approaches that do not require custom code.

So in the scenario where you want to auto number records with a combination of the parent record and a sequential number, the following is a no-code approach that I have used.

  1. Add a whole number field to the parent entity called “Counter.” Using a system business rule, default the value to 0.
  2. Add a workflow that runs on create of the child entity.
  3. Add a step to the workflow that increments the counter field on the parent record by 1.
  4. Add a step to the workflow that updates the child entity record and sets the name field to a combination of account name – counter field value.

The result will be a dependable synchronous automatic number that should work for basic requirements. Note that it will not re-use numbers should one of the child records get deleted. If more complex auto-numbering is required, a plugin is the recommended approach.

Share on FacebookTweet about this on TwitterShare on Google+

Leave a Reply

Your email address will not be published. Required fields are marked *