We’re setting up Dynamics CRM 2011 at my workplace and I had to figure out how to set up our pipeline. Here’s my solution:
I created a Sales Stage field that updates the Pipeline Phase and Probability fields on change. I followed Ayaz Ahmad’s solution for hooking up a javascript function to my Opportunity form and then wrote the following function (after some iteration).
function new_SalesStage_OnChange()
{
var new_salesstageAttr = Xrm.Page.getAttribute("new_salesstage");
var stepnameAttr = Xrm.Page.getAttribute("stepname");
var closeprobabilityAttr = Xrm.Page.getAttribute("closeprobability");
closeprobabilityAttr.setSubmitMode("always");
stepnameAttr.setSubmitMode("always");
if (new_salesstageAttr.getSelectedOption() == null)
{
stepnameAttr.setValue("");
closeprobabilityAttr.setValue(null);
}
else
{
var ssVal = new_salesstageAttr.getSelectedOption().text;
var pl = ssVal.lastIndexOf('%');
var probability = parseInt(ssVal.substring(pl-2, pl));
stepnameAttr.setValue(ssVal);
closeprobabilityAttr.setValue(probability);
}
}
The biggest tricks were:
- Using LOWER CASE names for my field names. This breaks if I use getAttribute(“new_SalesStage”), which is it’s real name. Booo, Microsoft!!!
- Handling the null value.
- Using the setSubmitMode(“always”) call to make sure the readonly fields were beiing saved.
This solution should have been quicker but I learned a lot on it.
2 comments:
Nice post! Helped me a lot. I did a similar scenario. However in my example it calculates the probability based on a matrix which is set like RATING X SALES STAGE
For example:
RATING Cold X SALES STAGE Prospect = 5%
RATING Warm X SALES STAGE Prospect = 25%
RATING Hot X SALES STAGE Prospect = 50%
RATING Cold X SALES STAGE Proposal = 25%
[...]
I was stuck with the read-only issue, and I even knew that I had to set the submission mode. However I was getting stuck as I had to declare a variable. Thanks again!
Thanks! Appreciate the no-nonsense posts like this...without the air of "I'm an expert".
Post a Comment