The requirement
I've been asked to automatically associate the account manager of a customer to an opportunity, if it takes place in a branch.
In our case customers are always contacts and the main account manager of the client is a lookup field.
The linking happens via a n:n relationship between the opportunity entity and a custom employee entity (schemanname = tt_mitarbeiter). The corresponding subgrid showing the participants of type employee is shown in an own section on the opportunity form.
Options
I know there are third party tools available, like the 365 Workflow Tools that are able to fullfill this requirement. But since I am working in a banking environment, I prefer to write the necessary code on my own.
So I decided to go for a custom workflow activity, which first checks if the account manager is already associated to the opportunity, or not. If the account manager isn't added so far, he/she is associated to the current opportunity.
Creating a custom workflow
To create a custom workflow, you need to create a custom workflow project in Visual Studio. I use the Dynamics 365 Developer extensions for that purpose.
In the workflow project you need to add a workflow class:
Then you need to write your code.
Input/Output parameters
Input/Output parameters are used to pass information from a workflow to a custom workflow activity or vice versa.
In my case I defined one mandatory input parameter, where I pass the account manager to the workflow activity.
Check if account manager is already linked
Next I check with a RetrieveMultiple request, weither the account manager of the customer of the current opportunity has been linked:
Associate account manager
In case the count of the RequestMultiple request is 0, I associated the account manager to the opportunity.
Register custom workflow
If you are done with development and you've built your workflow project, you can register it using the Plugin Registration Tool.
Adding the custom workflow activity to a workflow
In my case I created a real time workflow that triggers, when a new opportunity is created or when the field location (-> branch) is being changed.
Finally I added a check condition, if the location equals branch and then I can select our newly developed custom workflow activity at "add steps":
By clicking on properties, the input parameter (account manager) can be defined:
Now, whenever an opportunity with location branch is being created, or the location of an existing opportunity is being changed to branch, the account manager is automatically linked:
Comments
Post a Comment