Solved

CRM 4.0 javascript error

Posted on 2009-04-06
1
682 Views
Last Modified: 2012-05-11
This code when run as an onchange event on the field works fine when I paste it into the onload for the form it always throws an error for this section:
{
            oTempArray[iIndex] = ocategoryofservice.originalPicklistOptions[i];
            iIndex++;
      }

FULL CODE BELOW

var ocasetypecode = crmForm.all.casetypecode ;

var iStartIndex = -1;
var iEndIndex = -1;

switch (ocasetypecode .SelectedText)
{
      case "Training":
            iStartIndex = 1;
            iEndIndex = 14;
            break;

      case "Technical Assistance":
            iStartIndex = 15;
            iEndIndex = 31;
            break;

                       case "Resource Development":
            iStartIndex = 32;
            iEndIndex = 34;
            break;

                       case "Advocacy":
            iStartIndex = 35;
            iEndIndex = 36;
            break;



}

var ocategoryofservice= crmForm.all.new_categoryofservice;

if (iStartIndex > -1 &&  iEndIndex > -1)
{
      // Create a new array, which will hold the new picklist options
      var oTempArray = new Array();

      // Initialize the index for the temp array
      var iIndex = 0;

            for (var i = iStartIndex; i <= iEndIndex; i++)
      {
            oTempArray[iIndex] = ocategoryofservice.originalPicklistOptions[i];
            iIndex++;
      }

            ocategoryofservice.Options = oTempArray;

            ocategoryofservice.Disabled = false;
}
else
{
            ocategoryofservice.DataValue = null;
      ocategoryofservice.Disabled = true;
}
0
Comment
Question by:biotec
1 Comment
 
LVL 2

Accepted Solution

by:
t-joe earned 500 total points
ID: 24085310
Hello biotec,

have you seen this post: http://social.msdn.microsoft.com/Forums/en-US/isv/thread/f0f8ff49-30f2-46e2-8174-213a7810c357/

If the error is regarding the originalPicklistOptions attribute then it seems you have to set it earlier.

To clarify, "Marius August" wants you to leave the original code in the onchange event, and then put his code in onload. In his code he makes a manual call to the onchange event with the call new_sector_onchange0();
Since your field is called casetypecode, your call should be casetypecode_onchange0();

It should also be possible to keep all the code in the onload event, then you will have to declare your code in a separate function and call that instead.

Let me know if any of this helps!
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
how would you interpret lines 3 36
jquery - show / hide div depending on day and time 19 46
Converting dates in JavaScript 2 31
how can i test my code? 1 33
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
Having trouble getting your hands on Dynamics 365 Field Service or Project Service trial? Worry No More!!!
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now