tags:

views:

468

answers:

3

Hi All,

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 :)

+1  A: 

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

Nordes
yes, i thought that way too. maybe the obstacle is to find enough plug-in sample code resources since there are only few samples in SDK :)sorry for the late response
cyrene
it's ok ;). Actually, it's not that hard to do even if you don't have any sample. To search the opp code starting with the acc code you can do a "kind of" advanced search and then play around with the data.Go read/download : http://www.codeplex.com/fetchxmlbuilder
Nordes
+1  A: 

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.

Rihan Meij
thanks for your opinion, rihan! :D
cyrene
A: 

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.)

grega g