Recently we had a requirement to use auto numbers for lead records.
However, based on where the lead records are being created from, we wanted to specify a different prefix to it.
For leads created manually, the format should be prefixed “L” followed by “– “and then 10 digit sequence number.
L-{SEQNUM:10}
And if created through API the prefix should be B.
B-{SEQNUM:10}
To achieve this, we can define an auto-number field with the following format.
Next, we can have a bool field (default – false) in the lead table, to identify if it is being created from the API, which we can set while creating the lead record through API.
And a Pre Create Plugin on Lead to check the value of that field.
If it is set (true), that we can replace the Prefix from L to B in the auto-number field within the context.
In the Pre Create plugin, we get the next sequence in the auto-number field, so simply replacing/setting the value of the auto numbering field did the trick.
Lead created through Web Application –
Lead created through API –
Here uniqueness was more important than the next sequence of the lead record so this solution worked.
Also check –
https://jonasr.app/2020/03/anm-unique-seq/
https://nishantrana.me/2021/11/09/few-key-points-auto-number-field-in-dataverse-dynamics-365-ce-crm/
Hope it helps..
Is this a supported way though?
LikeLike
Just noticed your comment Danish :). Yes supported as we are using plugin only.
LikeLike