cyrene
cyrene

Reputation: 119

Auto generated numbering in CRM Opportunity

Suppose I add one field called Acc Code in Account. In this field, user can manually input 2 digits of alphabets. Example: user create Account with Name "Successful Company Pty Ltd" and user manually inputs the Acc Code with "SC". user create another Account with Name "Another Company Pty Ltd" and user inputs the Acc Code with "AC".

On Opportunity, I add one field called Opp Code. This field contains 5 digits, 2 digits alphabets of Acc Code from Potential Customer (Account that is referred by Opportunity as customer) and 3 digits are autonumbering. The autonumbering depends on the Potential Customer. That means, for Potential Customer "Succesful Company Pty Ltd" the Opp Code is SC001, if there is a new Opportunity for it again, the code is SC002. If the Opportunity is created for Potential Customer "Another Company Pty Ltd" then the beginning Opp Code is AC001.

I need suggestion on how to implement the automated numbering depends on Potential Customer. I imagined using Plug-in, but not sure on how to search the last Opp Code number (since the number depends on Acc Code). Would anyone mind helping or giving an example on how to do this?

Thank you :)

Upvotes: 1

Views: 1597

Answers (3)

grega g
grega g

Reputation: 1089

Here's how I would do:

  1. create additional field on Account entity that would hold counter for opportunities
  2. when new Account is created set that field to 1 as that will be next number assigned to opportunity with that account as potential customer.
  3. when new opportunity is created, look up next number in account's field.
  4. assign that number to opportunity opp code
  5. increase account's number.

Steps 3 - 5 should be in plugin. Its important that they are executed as atomic operation and only one at the time. Use Mutex class to ensure that, since crm plugins are executed in multiple processes. (unless you have farm deployment. In that case mutex won't work.)

Upvotes: 0

Rihan Meij
Rihan Meij

Reputation: 1759

The plugin route does seem to be the best approach. I would begin by drawing out my process on a white board or piece of paper. You need to be very clear when what happens. Then you can start writing the plugin because you know what needs to happen where.

I am sure you have found plenty of resources of how to write Crm plugins. The toughest thing with developing for Crm is the toughest thing for any type of development, you have to decided how you going to do things. For example:

  • can a Opportunity be created / modified from the outlook client?
  • What happens if I have used a contact instead of a account?
  • Will it then take the parent account of the contact?
  • Can a account be changed on the opportunity once it has been created?

Once you have a very clear picture of what you want to do, I am sure there is a lot of help that the community can give you, when you run into specific problems.

Based on all of these questions, will be the answer, in how best to approach this problem. It might be that the customer expects this for very little, and that you have to come up with a solution that is perhaps not very robust, but quicker to develop than a full plugin.

Upvotes: 1

Nordes
Nordes

Reputation: 2521

Here's a pseudo code solution.

  • You could do a search to get all "Opp Code" starting with "Acc Code".
  • You then parse those "Opp Code" (You know it's AA000, so you remove those 2 first letters) and take the maximum number and then add 1.
  • You then set the new "Opp Code" to your opportunity.

Good luck

Upvotes: 1

Related Questions