Answered by:
Error if I choose not to fill a field value or Option Set value.

Question
-
Hey guys,
So basically I have couple of option sets from where I choose a value and based on those value I calculate the result.
I have 7 option sets, but it is not necessary that all 7 are used. SO if someone only chooses to use values from 3 of the option sets and leave the rest empty, the user gets the following error.There was an error in the field customized event.
Event: onSave
Error: Unable to get property 'value' of undefined or null reference.
now I realize that this error means that the other option set values are empty but how do I get past this?
I am using javascript to use the value from option set to multiply to a value in text field and get my result. Here is my code
function cashTotal() { if (Xrm.Page.ui.getFormType() == 1) { var bill1 = Xrm.Page.getAttribute("inmate_cashbills1").getSelectedOption().value; var bill1Text = Xrm.Page.getAttribute("inmate_cashbill1_text").getValue(); var result1 = bill1 * bill1Text; Xrm.Page.getAttribute("inmate_total1").setValue(result1); var bill2 = Xrm.Page.getAttribute("inmate_cashbills2").getSelectedOption().value; var bill2Text = Xrm.Page.getAttribute("inmate_cashbill2_text").getValue(); var result2 = bill2 * bill2Text; Xrm.Page.getAttribute("inmate_total2").setValue(result2); var bill5 = Xrm.Page.getAttribute("inmate_cashbillls5").getSelectedOption().value; var bill5Text = Xrm.Page.getAttribute("inmate_cashbill5_text").getValue(); var result5 = bill5 * bill5Text; Xrm.Page.getAttribute("inmate_total5").setValue(result5); var bill10 = Xrm.Page.getAttribute("inmate_cashbills10").getSelectedOption().value; var bill10Text = Xrm.Page.getAttribute("inmate_cashbill10_text").getValue(); var result10 = bill10 * bill10Text; Xrm.Page.getAttribute("inmate_total10").setValue(result10); var bill20 = Xrm.Page.getAttribute("inmate_cashbills20").getSelectedOption().value; var bill20Text = Xrm.Page.getAttribute("inmate_cashbill20_text").getValue(); var result20 = bill20 * bill20Text; Xrm.Page.getAttribute("inmate_total20").setValue(result20); var tmp = result1 + result2 + result5 + result10 + result20; Xrm.Page.getAttribute("inmate_cashtotal").setValue(tmp); }
Basically "inmate_cashbills1" is the value from option set.
"inmate_cashbill1_text" is a value that is multiplied by the option set value to give a result.Wednesday, November 6, 2013 4:05 PM
Answers
-
I found the solution. Instead of
var bill1 = Xrm.Page.getAttribute("inmate_cashbills1").getSelectedOption().value;
DO
var bill1 = Xrm.Page.getAttribute("inmate_cashbills1").getValue();
Still thank you for your help
Thursday, November 7, 2013 1:08 PM
All replies
-
The simplest way would probably be to do a try catch around each or to evaluate the value of the option set prior to using it.Wednesday, November 6, 2013 4:12 PM
-
Why would I do a try catch?
I know the error and the reason behind the error. I just want to know what to do if I DONT WANT TO USE ALL the option set and calculate my result based on one or two of them?Wednesday, November 6, 2013 4:53 PM -
The try catch is just a way to evaluate and keep going...you're not actually doing anything with the exception...
try{
var bill1 = Xrm.Page.getAttribute("inmate_cashbills1").getSelectedOption().value; var bill1Text = Xrm.Page.getAttribute("inmate_cashbill1_text").getValue(); var result1 = bill1 * bill1Text; Xrm.Page.getAttribute("inmate_total1").setValue(result1); }
catch(e){}
try{ var bill2 = Xrm.Page.getAttribute("inmate_cashbills2").getSelectedOption().value; var bill2Text = Xrm.Page.getAttribute("inmate_cashbill2_text").getValue(); var result2 = bill2 * bill2Text; Xrm.Page.getAttribute("inmate_total2").setValue(result2);
}
catch(e){}
- Edited by burnsj2013 Wednesday, November 6, 2013 6:10 PM
Wednesday, November 6, 2013 6:10 PM -
it starts giving me another error "you need to choose the enter value between 0 and 1,000,000,000" and then it closes the form. It is catching an exception of the field when i do not use one of the option set.
Thursday, November 7, 2013 12:36 PM -
I found the solution. Instead of
var bill1 = Xrm.Page.getAttribute("inmate_cashbills1").getSelectedOption().value;
DO
var bill1 = Xrm.Page.getAttribute("inmate_cashbills1").getValue();
Still thank you for your help
Thursday, November 7, 2013 1:08 PM