CRM 4 - Custom entities and Case form.

Asked By John Morlan
03-Nov-09 06:31 AM
Earn up to 0 extra points for answering this tough question.

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. 

  Use ID

F Cali replied to John Morlan
05-Nov-09 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

Create New Account