locked
Lookup Filter help multiple OR RRS feed

  • Question

  • I have 3 Account lookups that I need to use to filter a contact lookup.  I'm getting errors, that i just can;t seem to pinpoint the incorrect syntax.

     error: invalid cast exception

    //Filtered Lookup for A, B, G
    //
    FilterLookup = function (admin, group, broker, crmField, relationshipfield) {
      var adminID;
      var groupID;
      var brokerID;
      var crmField;
      var relationshipfield;
      var lookupItem;
    
      lookupItem = new Array;
      lookupItem = crmForm.all[admin].DataValue;
      if (lookupItem && lookupItem[0] != null) {
        adminID = lookupItem[0].id;
        var adminSoap = ('"' + "<condition attribute='" + relationshipfield + "' operator='eq' value='" + adminID + "'/>" + '"');
      }
      
      lookupItem = new Array;
      lookupItem = crmForm.all[group].DataValue;
      if (lookupItem && lookupItem[0] != null) {
      groupID = lookupItem[0].id;
      var groupSoap = ('"' + "<condition attribute='" + relationshipfield + "' operator='eq' value='" + groupID + "'/>" + '"');
      }
    
      lookupItem = new Array;
      lookupItem = crmForm.all[broker].DataValue;
      if (lookupItem && lookupItem[0] != null) {
      brokerID = lookupItem[0].id;
      var brokerSoap = ('"' + "<condition attribute='" + relationshipfield + "' operator='eq' value='" + brokerID + "'/>" + '"');
      }
      
      if (adminID == null && groupID == null && brokerID == null) {
        crmForm.all[crmField].Disabled = true;
      }
      else {
        crmForm.all[crmField].lookupbrowse = 1;
    
        crmForm.all[crmField].AddParam("search", "<fetch mapping='logical'><entity name='contact'>" +
        "<filter type ='or'>" +
        adminSoap +
        groupSoap +
        brokerSoap +
      "</filter></entity></fetch>");
      }
    }
    FilterLookup('new_accountid', 'new_groupid', 'new_brokerid', 'new_primarycontactid', 'parentcustomerid');

    Please help, i'm going nuts commenting and alerting to no avail.

    :) thank you

     


    Withers
    Monday, May 3, 2010 11:57 PM

Answers

  • After looking at the code more carefully, it seems that there are a few more problems. So this is new code that I came up: 

     

    //Filtered Lookup for A, B, G
    //
    FilterLookup = function (admin, group, broker, crmField, relationshipfield) {
     var adminID;
     var groupID;
     var brokerID;
     var lookupItem;
    
     lookupItem = crmForm.all[admin].DataValue;
     adminID = (lookupItem == null) ? null : lookupItem[0].id;
     var adminSoap = (adminID == null) ? "" : "<condition attribute='" + relationshipfield + "' operator='eq' value='" + adminID + "'/>";
    
     lookupItem = crmForm.all[group].DataValue;
     groupID = (lookupItem == null) ? null : lookupItem[0].id;
     var groupSoap = (groupID == null) ? "" : "<condition attribute='" + relationshipfield + "' operator='eq' value='" + groupID + "'/>";
    
     lookupItem = crmForm.all[broker].DataValue;
     brokerID = (lookupItem == null) ? null : lookupItem[0].id;
     var brokerSoap = (brokerID == null) ? "" : "<condition attribute='" + relationshipfield + "' operator='eq' value='" + brokerID + "'/>";
    
     if (adminID == null && groupID == null && brokerID == null) {
      crmForm.all[crmField].Disabled = true;
     }
     else {
      crmForm.all[crmField].lookupbrowse = 1;
    
      crmForm.all[crmField].AddParam("search", "<fetch mapping='logical'><entity name='contact'>" +
                 "<filter type ='or'>" +
                 adminSoap +
                 groupSoap +
                 brokerSoap +
                 "</filter></entity></fetch>");
     }
    }
    FilterLookup('new_accountid', 'new_groupid', 'new_brokerid', 'new_primarycontactid', 'parentcustomerid');

     


    Daniel Cai | http://danielcai.blogspot.com
    Tuesday, May 4, 2010 2:00 AM

All replies

  • The following two lines should be removed, as they are hiding the parameters passed to the function. 

     var crmField;
     var relationshipfield;

    Daniel Cai | http://danielcai.blogspot.com
    Tuesday, May 4, 2010 1:29 AM
  • I added what you said and received the same error so i took out the quotes:

    //Filtered Lookup for A, B, G
    //
    FilterLookup = function (admin, group, broker, crmField, relationshipfield) {
      var crmField;
      var relationshipfield;
      var adminID;
      var groupID;
      var brokerID;
      var crmField;
      var relationshipfield;
      var lookupItem;
    
      lookupItem = new Array;
      lookupItem = crmForm.all[admin].DataValue;
      if (lookupItem && lookupItem[0] != null) {
        adminID = lookupItem[0].id;
        var adminSoap = ("<condition attribute='" + relationshipfield + "' operator='eq' value='" + adminID + "'/>");
      }
      
      lookupItem = new Array;
      lookupItem = crmForm.all[group].DataValue;
      if (lookupItem && lookupItem[0] != null) {
      groupID = lookupItem[0].id;
      var groupSoap = ("<condition attribute='" + relationshipfield + "' operator='eq' value='" + groupID + "'/>");
      }
    
      lookupItem = new Array;
      lookupItem = crmForm.all[broker].DataValue;
      if (lookupItem && lookupItem[0] != null) {
      brokerID = lookupItem[0].id;
      var brokerSoap = ("<condition attribute='" + relationshipfield + "' operator='eq' value='" + brokerID + "'/>");
      }
      
      if (adminID == null && groupID == null && brokerID == null) {
        crmForm.all[crmField].Disabled = true;
      }
      else {
        crmForm.all[crmField].lookupbrowse = 1;
    
        crmForm.all[crmField].AddParam("search", "<fetch mapping='logical'><entity name='contact'>" +
        "<filter type ='or'>" +
        adminSoap +
        groupSoap +
        brokerSoap +
      "</filter></entity></fetch>");
      }
    }
    FilterLookup('new_accountid', 'new_groupid', 'new_brokerid', 'new_primarycontactid', 'parentcustomerid');


    Withers
    Tuesday, May 4, 2010 1:59 AM
  • After looking at the code more carefully, it seems that there are a few more problems. So this is new code that I came up: 

     

    //Filtered Lookup for A, B, G
    //
    FilterLookup = function (admin, group, broker, crmField, relationshipfield) {
     var adminID;
     var groupID;
     var brokerID;
     var lookupItem;
    
     lookupItem = crmForm.all[admin].DataValue;
     adminID = (lookupItem == null) ? null : lookupItem[0].id;
     var adminSoap = (adminID == null) ? "" : "<condition attribute='" + relationshipfield + "' operator='eq' value='" + adminID + "'/>";
    
     lookupItem = crmForm.all[group].DataValue;
     groupID = (lookupItem == null) ? null : lookupItem[0].id;
     var groupSoap = (groupID == null) ? "" : "<condition attribute='" + relationshipfield + "' operator='eq' value='" + groupID + "'/>";
    
     lookupItem = crmForm.all[broker].DataValue;
     brokerID = (lookupItem == null) ? null : lookupItem[0].id;
     var brokerSoap = (brokerID == null) ? "" : "<condition attribute='" + relationshipfield + "' operator='eq' value='" + brokerID + "'/>";
    
     if (adminID == null && groupID == null && brokerID == null) {
      crmForm.all[crmField].Disabled = true;
     }
     else {
      crmForm.all[crmField].lookupbrowse = 1;
    
      crmForm.all[crmField].AddParam("search", "<fetch mapping='logical'><entity name='contact'>" +
                 "<filter type ='or'>" +
                 adminSoap +
                 groupSoap +
                 brokerSoap +
                 "</filter></entity></fetch>");
     }
    }
    FilterLookup('new_accountid', 'new_groupid', 'new_brokerid', 'new_primarycontactid', 'parentcustomerid');

     


    Daniel Cai | http://danielcai.blogspot.com
    Tuesday, May 4, 2010 2:00 AM
  • Thank you! you are a genius!!!!

    Withers
    Tuesday, May 4, 2010 2:05 AM
  • I am guessing this is not for version 4.0 but for a later version of CRM.
    Thursday, October 27, 2011 7:13 PM