Answered by:
CRM OPTIONSET THROWING ERROR URGENT!!

Question
-
I have a option set having
Small Business as value 1
Lenders as value 2
My code is
function Form_onload()
{
if (Xrm.Page.getAttribute("new_counselingfor").getText() == "Lenders"){
alert("Lenders");
}if (Xrm.Page.getAttribute("new_counselingfor").getValue() == 1)
{
alert("sb");
}}
but this is throwing me an error
There was an error with this fields customized event
Field : Window
Event: onload
error: unable to get value of the proprty "getText:" oject is null or undefined
Thursday, August 9, 2012 3:43 PM
Answers
-
Are you sure your field name uses the "new" prefix and not a custom one that you defined? Or is there a typo in "new_counselingfor" or is the field name something else?
I can reproduce this error if I have an incorrect field name on the line that references 'getValue()'
Jason Lattimer
- Marked as answer by CRMAG Thursday, August 9, 2012 6:01 PM
- Edited by JLattimerMVP, Moderator Thursday, August 9, 2012 6:10 PM
Thursday, August 9, 2012 5:42 PMModerator
All replies
-
Try this:
var YourValue = Xrm.Page.data.entity.attributes.get("yourField").getSelectedOption().text;
Jason Lattimer
Thursday, August 9, 2012 3:54 PMModerator -
ok changed code to
function Form_onload()
{
var YourValue = Xrm.Page.data.entity.attributes.get("new_counselingfor").getSelectedOption().text;
alert(YourValue);}
this now throw an error saying
unable to get value of the proprty "getSelectedOption" oject is null or undefined
Thursday, August 9, 2012 4:06 PM -
When the form loads - is the option set to a value by default or is it empty? If it is empty when the form loads you'll see an error because there is no 'selected option'.
Maybe try testing your code on the OnChange event for that option set.
Jason Lattimer
Thursday, August 9, 2012 4:34 PMModerator -
Hi,
Try this
if(Xrm.Page.getAttribute("new_counselingfor").getValue()!=null)
{
var YourValue=Xrm.Page.getAttribute("new_counselingfor").getSelectedOption().text;
alert(YourValue);
}
Conatact Me
Follow me on Twitter
Make sure to "Vote as Helpful" and "Mark As Answer",if you get answer of your question.- Proposed as answer by Andrii ButenkoMVP, Moderator Thursday, August 9, 2012 5:03 PM
Thursday, August 9, 2012 4:56 PMModerator -
so this time I try this code and I have set "small Business" as default in my option set
Still getting error
unable to get value of the proprty "getValue" oject is null or undefined
its simple but still frustrating can someone help me out here
function Form_onload()
{if(Xrm.Page.getAttribute("new_counselingfor").getValue() != null)
{
var YourValue=Xrm.Page.getAttribute("new_counselingfor").getSelectedOption().text;
alert(YourValue);
}}
Thursday, August 9, 2012 5:31 PM -
Are you sure your field name uses the "new" prefix and not a custom one that you defined? Or is there a typo in "new_counselingfor" or is the field name something else?
I can reproduce this error if I have an incorrect field name on the line that references 'getValue()'
Jason Lattimer
- Marked as answer by CRMAG Thursday, August 9, 2012 6:01 PM
- Edited by JLattimerMVP, Moderator Thursday, August 9, 2012 6:10 PM
Thursday, August 9, 2012 5:42 PMModerator -
Jason,
Indeed u caught me right, it was a spellingmistake, now it works.
Toooo bad I need to clear my head.
Thanks A LOT Jason and Mahender.
AG
Thursday, August 9, 2012 6:01 PM