locked
Quick question on duplicate detection RRS feed

  • Question

  • Hi

    When a user enters an account name in a custom attribute on the Lead Entity, I want to know if the account name already exists in CRM. Can this be done at the level of customizations or javascripts without the plugin ?

    Friday, April 23, 2010 11:22 PM

Answers

  • If you use CRM Web Service Toolkit, you may write script like this: 

     

    function checkIfAccountExists(name) {
     var fetchXml =
    "<fetch mapping='logical' aggregate='true'>" +
     "<entity name='account'>" +
      "<attribute name='accountid' aggregate='count' alias='count' />" +
      "<filter>" +
       "<condition attribute='name' operator='eq' value='" + name + "' />" +
      "</filter>" +
     "</entity>" +
    "</fetch>";
    
     var fetchedAccounts = CrmServiceToolkit.Fetch(fetchXml);
    
     return fetchedAccounts[0].getValue('count') > 0;
    }
    
    if (checkIfAccountExists(crmForm.all.new_myfield)) {
     alert("The same name account already exists. ");
    }

     

    If you don't like to use the toolkit, you may refer to SDK's CrmService.Fetch method and use the above query to make service call. 

    Hope this helps. 

    Saturday, April 24, 2010 1:18 AM

All replies

  • Yes, you can use JavaScript to make service call to see if it already exists. 
    Daniel Cai | http://danielcai.blogspot.com
    Friday, April 23, 2010 11:30 PM
  • How, any links, please?
    Friday, April 23, 2010 11:41 PM
  • If you use CRM Web Service Toolkit, you may write script like this: 

     

    function checkIfAccountExists(name) {
     var fetchXml =
    "<fetch mapping='logical' aggregate='true'>" +
     "<entity name='account'>" +
      "<attribute name='accountid' aggregate='count' alias='count' />" +
      "<filter>" +
       "<condition attribute='name' operator='eq' value='" + name + "' />" +
      "</filter>" +
     "</entity>" +
    "</fetch>";
    
     var fetchedAccounts = CrmServiceToolkit.Fetch(fetchXml);
    
     return fetchedAccounts[0].getValue('count') > 0;
    }
    
    if (checkIfAccountExists(crmForm.all.new_myfield)) {
     alert("The same name account already exists. ");
    }

     

    If you don't like to use the toolkit, you may refer to SDK's CrmService.Fetch method and use the above query to make service call. 

    Hope this helps. 

    Saturday, April 24, 2010 1:18 AM
  • Let me try this out. Thanks

    Saturday, April 24, 2010 1:20 AM