Solved

CRM 4.0 javascript error

Posted on 2009-04-06
1
680 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
This article discusses how to create an extensible mechanism for linked drop downs.
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…

746 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

12 Experts available now in Live!

Get 1:1 Help Now