Overview
In this scenario, we require that both the Contact and Account entity share the AutoNumber count.
Whenever an Account or a Contact is created, we want their respective new_autonumber field to be filled automatically. We want this field to be iterated from the last Contact or Account.
Note 1 : The North52 autonumber solution guarantees 100% uniqueness for autonumbers when a single entity is involved. In this KB article , two entities are involved so there is a small chance that duplicate autonumbers could occur under heavy system load. So please be aware of this risk if using the KB article.
Note 2: We use a custom field on the Account entity called new_autonumber and another custom field on the Contact entity also called new_autonumber. You will need to create these first or replace wherever you see new_autonumber with your own field.
North52 Decision Suite
The North52 Decision Suite solution works like this:
- Two Formulas are created - one that triggers on the creation of an Account, the other on the creation of a Contact
- Both Formulas will search for the highest Account AutoNumber and the highest Contact AutoNumber using 2 Fetch Xml queries
- They will compare the two AutoNumbers and take the highest value
- They will set the AutoNumber for Account/Contact to be the current highest AutoNumber + 1
Set up Formulas and Fetch Xml Queries
Formula 1: AutoNumber Multiple Entities - Account
- Navigate to Settings > N52 Formula
- Create a new formula, setting the following values in the Formula Guide:
- Source Entity set to Account
- Set Formula Type to Auto Number
- Select the Classic Editor
- Change the Name of the formula to AutoNumber Multiple Entities - Account
- Expand Source & Target
- Set Target Property to AutoNumber
- Copy and paste the following into the Classic Editor (you may need to replace the new_autonumber field reference with your own field schema name)
Smartflow( SetVar('ContactAutoNumberwithPrefix',FindValueFD('Highest Contact AutoNumber - for Accounts','new_autonumber','0','true')), SetVar('AccountAutoNumberwithPrefix',FindValueFD('Highest Account AutoNumber - for Accounts','new_autonumber','0','true')), SetVar('ContactAutoNumber', Replace(GetVar('ContactAutoNumberwithPrefix'),'CON-','')), SetVar('AccountAutoNumber',Replace(GetVar('AccountAutoNumberwithPrefix'),'ACC-','')), SetVar('LatestAutoNumber',MaxOf(GetVar('ContactAutoNumber'),GetVar('AccountAutoNumber'))), 'ACC-'+PadLeft(GetVar('LatestAutoNumber')+ 1,9,'0') )
- Click Save
Formula 1 Fetch Xml (1): Highest Contact AutoNumber - for Accounts
From the Formula AutoNumber Multiple Entities- Account:
- Select the Fetch-Xml tab
- Click the + button
- Set Name to Highest Contact AutoNumber - for Accounts
- For Query, copy and paste the following Fetch Xml (you may need to replace the new_autonumber field reference with your own field schema name):
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"> <entity name="contact"> <attribute name="fullname" /> <attribute name="contactid" /> <attribute name="new_autonumber" /> <order attribute="new_autonumber" descending="true" /> </entity> </fetch>
- Click Save & Close
Formula 1 Fetch Xml (2): Highest Account AutoNumber - for Accounts
From the Formula AutoNumber Multiple Entities- Account:
- Click on the Fetch-Xml tab
- Click the + button
- Set Name to Highest Account AutoNumber - for Accounts
- For Query, copy and paste the following Fetch Xml (you may need to replace the new_autonumber field reference with your own field schema name):
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"> <entity name="account"> <attribute name="name" /> <attribute name="accountid" /> <attribute name="new_autonumber" /> <order attribute="new_autonumber" descending="true" /> </entity> </fetch>
- Click Save & Close
Formula 2: AutoNumber Multiple Entities - Contact
- Navigate to Settings > N52 Formula
- Create a new formula, setting the following values in the Formula Guide:
- Source Entity set to Contact
- Set Formula Type to Auto Number
- Select the Classic Editor
- Change the Name of the formula to AutoNumber Multiple Entities - Contact
- Expand Source & Target
- Set Target Property to AutoNumber
- Paste the following code into the Classic Editor (you may need to replace the new_autonumber field reference with your own field schema name):
Smartflow( SetVar('ContactAutoNumberwithPrefix',FindValueFD('Highest Contact AutoNumber - for Contacts','new_autonumber','0','true')), SetVar('AccountAutoNumberwithPrefix',FindValueFD('Highest Account AutoNumber - for Contacts','new_autonumber','0','true')), SetVar('ContactAutoNumber', Replace(GetVar('ContactAutoNumberwithPrefix'),'CON-','')), SetVar('AccountAutoNumber',Replace(GetVar('AccountAutoNumberwithPrefix'),'ACC-','')), SetVar('LatestAutoNumber',MaxOf(GetVar('ContactAutoNumber'),GetVar('AccountAutoNumber'))), 'CON-'+PadLeft(GetVar('LatestAutoNumber')+ 1,9,'0') )
- Click Save
Formula 2 Fetch Xml (1): Highest Contact AutoNumber - for Contacts
From the Formula AutoNumber Multiple Entities - Contact:
- Click on the Fetch-Xml tab
- Click the + button
- Set the Name to be Highest Contact AutoNumber - for Contacts
- For Query, copy and paste the following Fetch Xml (you may need to replace the new_autonumber field reference with your own field schema name):
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"> <entity name="contact"> <attribute name="fullname" /> <attribute name="contactid" /> <attribute name="new_autonumber" /> <order attribute="new_autonumber" descending="true" /> </entity> </fetch>
- Click Save & Close
Formula 2 Fetch Xml (2): Highest Account AutoNumber - for Contacts
From the Formula AutoNumber Multiple Entities - Contact:
- Click on the Fetch-Xml tab
- Click the + button
- Set the Name to be Highest Account AutoNumber - for Contacts
- For Query, copy and paste the following Fetch Xml (you may need to replace the new_autonumber field reference with your own field schema name):
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false"> <entity name="account"> <attribute name="name" /> <attribute name="accountid" /> <attribute name="new_autonumber" /> <order attribute="new_autonumber" descending="true" /> </entity> </fetch>
- Click Save & Close