Hi Guido,
function OnChangeStage() {
var stage = Xrm.Page.getAttribute("company_stage").getText();
if ((stage.toString()).indexOf("100") > -1) {
Xrm.Page.getAttribute("closeprobability").setValue(100);
DafRequiredForStageMoreThan20();
AdminAccessRequired();
}
else if ((stage.toString()).indexOf("20") > -1) {
Xrm.Page.getAttribute("closeprobability").setValue(20);
}
else if ((stage.toString()).indexOf("30") > -1) {
Xrm.Page.getAttribute("closeprobability").setValue(30);
DafRequiredForStageMoreThan20();
}
else if ((stage.toString()).indexOf("40") > -1) {
Xrm.Page.getAttribute("closeprobability").setValue(40);
DafRequiredForStageMoreThan20();
}
else if ((stage.toString()).indexOf("60") > -1) {
Xrm.Page.getAttribute("closeprobability").setValue(60);
DafRequiredForStageMoreThan20();
}
else if ((stage.toString()).indexOf("75") > -1) {
Xrm.Page.getAttribute("closeprobability").setValue(75);
DafRequiredForStageMoreThan20();
}
else if ((stage.toString()).indexOf("90") > -1) {
Xrm.Page.getAttribute("closeprobability").setValue(90);
DafRequiredForStageMoreThan20();
}
else if ((stage.toString()).indexOf("10") > -1) {
Xrm.Page.getAttribute("closeprobability").setValue(10);
}
else {
Xrm.Page.getAttribute("closeprobability").setValue(0);
}
}
function DafRequiredForStageMoreThan20() {
var dafcount = Xrm.Page.getAttribute("company_dafcount").getValue();
var businessunit = Xrm.Page.getAttribute("company_opportunitybusinessunit").getText();
if (dafcount == 0 && ((businessunit.toString()).indexOf("UK") > -1)) {
alert("Please add a deal approval form before changing the opportunity stage to more than 30%.")
var options = Xrm.Page.getAttribute("company_stage").getOptions();
for (i = 0; i < options.length; i++) {
if (options[i].text.indexOf("20") > -1) {
Xrm.Page.getAttribute("company_stage").setValue(options[i].value);
Xrm.Page.getAttribute("closeprobability").setValue(20);
}
}
return false;
}
}
function AdminAccessRequired() {
var isAdmin = Xrm.Page.getAttribute("company_isadmin").getValue();
var unit = Xrm.Page.getAttribute("company_opportunitybusinessunit").getText();
if ((isAdmin != "true") && ((unit.toString()).indexOf("UK") > -1)) {
alert("You don't have the rights to set an opportunity to 100%. Please contact System Administrator.")
var options = Xrm.Page.getAttribute("company_stage").getOptions();
for (i = 0; i < options.length; i++) {
if (options[i].text.indexOf("90") > -1) {
Xrm.Page.getAttribute("company_stage").setValue(options[i].value);
Xrm.Page.getAttribute("closeprobability").setValue(90);
}
}
}
}
This is the query i have written. Please suggest.