locked
xrm weirdness? RRS feed

  • Question

  • Hello - Please see the test script below. For some reason test 1 and test 2 don't recognize the selected subject as "Return/Cancellation" but test 3 works successfully:

        var selectedVal = crmForm.all.subjectid.DataValue[0].name;
       
        //test 1 = false
        alert('is return/cancel = ' + selectedVal == 'Return/Cancellation');

        //test 2 = false
        alert('is return/cancel upper = ' + selectedVal.toUpperCase() == 'RETURN/CANCELLATION');

        //test 3 works
        var selectedSubjectValue = crmForm.all.subjectid.DataValue[0].name;
        if (selectedSubjectValue.toUpperCase() == "RETURN/CANCELLATION") { alert ('final test works'); }

    My question is why does test 1 and test 2 not recognize the selected value but test 3 works successfully? 

    Theoretically, shouldn't all 3 test results eval to true?

    Wednesday, June 19, 2013 8:31 PM

All replies

  • Because you didn't consider the + operator

    In fact the output of first alert is "false", not "is return/cancel = false"
    this happens because the == operator is comparing the string "is return/cancel = Return/Cancellation" with the string "Return/Cancellation" and of course they are not equal and the output is false.

    If you change the code to

     
    alert('is return/cancel = ' + (selectedVal == 'Return/Cancellation'));
    you will see the correct result

    My blog: www.crmanswers.net

    Wednesday, June 19, 2013 8:51 PM