I have an option set field that is that record status. When the user changes the record status, I want to do a few checks and if there are issues with the record I want to warn the user and reset the option. This code worked great until I added the java line to set the option field to the value I wanted. Does anyone know how to make this work?
function CheckBeforeClose() {
debugger;
var firstfail = 0
var secondfail = 0
alert (Xrm.Page.getAttribute("po_initialleadstatus").getSelectedOption().text);
if (Xrm.Page.getAttribute("po_initialleadstatus").getSelectedOption().text == "Closed - Passed on/Qualified Lead") {
alert("second check");
alert(Xrm.Page.getAttribute("po_facevalueoflifeinsurancepolicy").getValue());
if (Xrm.Page.getAttribute("po_facevalueoflifeinsurancepolicy").getValue() < 100000) {
alert("first fail");
firstfail = 1;
}
var now = new Date(); //Todays Date
var birthday =Xrm.Page.getAttribute("po_dateofbirth").getValue(); //Get the Date of Birth value
var diff = now.getMonth() - birthday.getMonth(); //Check to see if Birthday has already passed
alert("***"+diff);
if (diff > -1) //If Birthday has already occurred
{
var bd1 = now.getFullYear() - birthday.getFullYear();
//set the age attribute
//Xrm.Page.getAttribute("arcrp_age").setValue(bd1.toString());
var Age = bd1;
}
else //If Birthday has not already occurred
{
var bd2 = now.getFullYear() - birthday.getFullYear() - 1;
//Xrm.Page.getAttribute("arcrp_age").setValue(bd2.toString());
var Age = bd2;
}
alert(Age);
if (Age < 70) {
alert("hi");
secondfail = 1;
}
alert( firstfail);
if (firstfail == 1 || secondfail == 1) {
alert(firstfail);
alert(secondfail);
Xrm.Page.getAttribute(“po_initialleadstatus”).setValue('Closed - Does Not Quality');
alert("Caller is not qualified to pass on!");
}
}
}
The line that is failing and broke the script is: Xrm.Page.getAttribute(“po_initialleadstatus”).setValue('Closed - Does Not Qualify');
I have copied the value (Closed - Does Not Qualify). Straight from the field so I can't be wrong.
Thanks, Dale