Search EggHeadCafe's Job Board
EggHeadCafe Silverlight WPF ASP.NET VB.NET C# Excel SQL Server SharePoint
search
MicrosoftArticlesForumsFAQs
C# .NET
VB.NET
Visual Studio .NET
ADO.NET
Xml / Xslt
VB 6.0
.NET CF
GDI+
LINQ
Deployment
Security
FoxPro
Silverlight / WPF
Entity Framework
RIA Services

WebArticlesForumsFAQs
JavaScript
ASP
ASP.NET
WCF

DatabasesArticlesForumsFAQs
SQL Server
Access
Oracle
MySQL
Other Databases

OfficeArticlesForumsFAQs
Excel
Word
Powerpoint
Outlook
Publisher
Money

Non-MicrosoftArticlesForumsFAQs
NHibernate
Perl
PHP
Ruby
Java
Linux / Unix
Apple
Open Source

Operating SysArticlesForumsFAQs
Windows 7
Windows Server
Windows Vista
Windows XP
Windows Update
MAC
Linux / UNIX

Server PlatformsArticlesForumsFAQs
BizTalk
Site Server
Exhange Server
IIS

Graphic DesignArticlesForumsFAQs
Macromedia Flash
Adobe PhotoShop
Expression Blend
Expression Design
Expression Web

OtherArticlesForumsFAQs
Lounge
Subversion / CVS
Ask Dr. Dotnetsky
Active Directory
Networking
Uninstall Virus
Job Openings
Product Reviews
Search Engines
Resumes

 

  View Other JavaScript Posts   Ask New Question  Ask New Question With Power Editor

CRM 4 - Custom entities and Case form.
John Morlan posted at Tuesday, November 03, 2009 6:31 AM

Hi, Can you please provide me some advise on how to improve the following code:

var lookupItem = new Array;
var subjectchosen;

lookupItem = crmForm.all.subjectid.DataValue;

if (lookupItem[0] != null)
 {
    // The guid value of the lookup.
    alert(lookupItem[0].id);
    subjectchosen = lookupItem[0].id;
  }

 if (subjectchosen == '{10942DD5-AA96-DE11-A34A-0050569744FE}')
 {
    crmForm.all.new_productcompserialid_c.style.visibility = '';
    crmForm.all.new_productcompserialid_d.style.visibility = '';
  }
 else
 {
  if (subjectchosen == '{C8550C28-AB96-DE11-A34A-0050569744FE}')
    {
      crmForm.all.new_productairconserialid_c.style.visibility = '';
      crmForm.all.new_productairconserialid_d.style.visibility = '';
     }
  else
   {
     if (subjectchosen == '{A8116101-AB96-DE11-A34A-0050569744FE}')
     {
        crmForm.all.new_productckserialid_c.style.visibility = '';
        crmForm.all.new_productckserialid_d.style.visibility = '';
      }
    }
  }

My issue is that i have another 15 subjects to add!! Plus additional coding later to filter the results of the lookup. 

Reply    Reply Using Power Editor
  Rank Winnings Points
November 0 $0.00 0
October 0 $0.00 0
Use ID
F Cali provided a rated reply to John Morlan on Thursday, November 05, 2009 12:02 PM

One thing you can do to avoid this whole set of IF statements is to use the code you are searching for (the one you are comparing with subjectchosen) as the ID of your elements.

As an example, instead of using "new_productcompserialid_c" as the ID of your element, use "10942DD5-AA96-DE11-A34A-0050569744FE" instead.  Then all you have to do is use document.getElementById to get a handle on that element and change its visibility.

Regards,
SQL Server Helper

Reply    Reply Using Power Editor
How well do you know SQL? Find out with the free test assessment from SQL Server Helper:
http://www.sql-server-helper.com/free-test/default.aspx
  Rank Winnings Points
November 3 $65.00 168
October 0 $0.00 0