2

Just started with Javasript + Dynamics 2011 today and got stuck at the beginning itself. I've been trying simple steps as follow 1. Change the value on radio button 2. Call a function from Javascript, which will set two field enabled and disabled

Code is as follows

function navenabled()
{

    var navdata = Xrm.Page.getAttribute("new_currentnavclient").getValue;

    if (navdata == true)
    {
        Xrm.Page.getControl(“new_noofusers”).setDisabled(true);
        Xrm.Page.getControl(“new_navversion”).setDisabled(true);
    }
    else
    {
        Xrm.Page.getControl(“new_noofusers”).setDisabled(false);
                Xrm.Page.getControl(“new_navversion”).setDisabled(false);
    }

}

I'm getting the following error, when changing the value on 'Current Nav Client' field

enter image description here

Also see the steps that I have performed for JavaScript call

enter image description here

Can someone please tell where I'm doing wrong.

2 Answers 2

3

First problem is with this line:

var navdata = Xrm.Page.getAttribute("new_currentnavclient").getValue;

getValue is a method, so the right way is getValue()

var navdata = Xrm.Page.getAttribute("new_currentnavclient").getValue();

The second problem is with all the getControl lines, you are using smart quotes

“ ”

Instead you need to use simple quotation marks, so your code will be:

function navenabled()
{

    var navdata = Xrm.Page.getAttribute("new_currentnavclient").getValue();

    if (navdata == true)
    {
        Xrm.Page.getControl("new_noofusers").setDisabled(true);
        Xrm.Page.getControl("new_navversion").setDisabled(true);
    }
    else
    {
        Xrm.Page.getControl("new_noofusers").setDisabled(false);
        Xrm.Page.getControl("new_navversion").setDisabled(false);
    }

}
Sign up to request clarification or add additional context in comments.

2 Comments

Great- thanks! My problem has been solved. But this JavaScript is behaving unexpected and the error information is not valuable. Do you have any idea how to debug the JavaScript code properly on Google chrome.
you can google for "crm 2011 debug javascript" you will find several guides to debug, mostly with IE
0

What you can try to do is using the document.getElementById ("fieldname").checked property. This value is allways accurate.

3 Comments

document.getElementById is an unsupported customization, and for get values and manage controls there are the supported Xrm methods
Unsupported, what can I say, so be it. A long time ago I followed a course from Microsoft. They worked out a complete example. Turning to the next page it says. Keep in mind that this is unsupported.
Well, the teacher of the course you followed didn't tell you a more important rule: If there is a supported method to do one thing, use that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.