locked
Email to case with the Account name RRS feed

  • Question

  • Hi,

    I am having some requirements in Email to case functionality. While convertig the Email to case the Web page dialog will be open and in the "Customer" field the contact value is automatically loaded instead of customer name.

    The Email is having only the contact value and it is loading in the "Customer" filed. But I want to load the respective account name of that contact in the "Customer" field.

    How can I achieve this? Please help us to get the solution in this issue.

    Thanks in Advance,
    Manikandan R.
    Tuesday, November 17, 2009 4:47 AM

Answers

  • Hi ManikandanJon,

    we have done this requirement using java script code ..in Incident Entity ..Form Load Code...

    following is the code for this..

    please put this code on Case Form On Load Event and enable that event and let me know if there is any issue or problem regarding this..

    //Set Filter for responsible contact to be relevant account
    if(crmForm.all.customerid.DataValue != null)
    {
    
      SetRightCustomer();
    }
    
    function SetRightCustomer()
    {
     // if yes check if it is case
      if(crmForm.all.customerid.DataValue[0] !=null)
      {
        // if customer is selected as contact
        if(crmForm.all.customerid.DataValue[0].typename == "contact")
        {
          //if responsible contactid is not selected then
           if(crmForm.all.responsiblecontactid.DataValue == null)
          {
               ReplaceCustomer(crmForm.all.customerid.DataValue[0].id)       
           }
    
         }
       }
    
    }
    
    
    function ReplaceCustomer(contactId)  
    {  
    
     var xml = "" +  
     "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +  
     "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +  
     GenerateAuthenticationHeader() +  
     " <soap:Body>" +  
     "    <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
    "      <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" + 
    "        <q1:EntityName>contact</q1:EntityName>" + 
    "        <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" + 
    "          <q1:Attributes>" + 
    "            <q1:Attribute>contactid</q1:Attribute>" + 
    "            <q1:Attribute>parentcustomerid</q1:Attribute>" + 
    "          </q1:Attributes>" + 
    "        </q1:ColumnSet>" + 
    "        <q1:Distinct>false</q1:Distinct>" + 
    "        <q1:Criteria>" + 
    "          <q1:FilterOperator>And</q1:FilterOperator>" + 
    "          <q1:Conditions>" + 
    "            <q1:Condition>" + 
    "              <q1:AttributeName>contactid</q1:AttributeName>" + 
    "              <q1:Operator>Equal</q1:Operator>" + 
    "              <q1:Values>" + 
    "                <q1:Value xsi:type=\"xsd:string\">" + contactId+ "</q1:Value>" + 
    "              </q1:Values>" + 
    "            </q1:Condition>" + 
    "          </q1:Conditions>" + 
    "        </q1:Criteria>" + 
    "      </query>" + 
    "    </RetrieveMultiple>" + 
    "  </soap:Body>" + 
    "</soap:Envelope>" + 
    "";
    
    var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    
    xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
    xmlHttpRequest.send(xml);
    
    var resultXml = xmlHttpRequest.responseXML;
    
    //alert(resultXml);
    
    
    
    if(resultXml !=null)
    {    
        var accountId= retriveText(resultXml.selectNodes("//BusinessEntity/q1:parentcustomerid"));     
        if(accountId!="")
        {
              //Create an array to set as the DataValue for the lookup control.     
              var lookupData = new Array(); 
              
             //Create an Object add to the array.     
               var lookupItem= new Object();
          
             //Set the id, typename, and name properties to the object.     
              lookupItem.id = accountId;     
              lookupItem.typename = 'account';    
    
              var lookupname = retriveName(lookupItem.id);     
     
              lookupItem.name = lookupname;
    
             // Add the object to the array.       
              lookupData[0] = lookupItem; 
    
            //Set Responsible Contact from existing customer (as customer is contact)
            crmForm.all.responsiblecontactid.DataValue =  crmForm.all.customerid.DataValue;
    
             // Set the value of the lookup field to the value of the array.           
              crmForm.all.customerid.DataValue = lookupData; 
        
          } 
    
     }
    
    }
    
    
    
    function retriveText(InputNode)
    {
      var text = "";
    
         if (InputNode !=null)
         {
            //alert(InputNode[0].text);
            if(InputNode[0]!=null)
            {
                text =InputNode[0].text;    
            }
         } 
    
     return text;
    }
    
    
    function retriveName(accountNodeId)
    {
      var textReturn = "";
    
         if (accountNodeId!=null)
         {
             var xml = "" +  
     "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +  
     "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +  
     GenerateAuthenticationHeader() +  
     " <soap:Body>" +  
     "    <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
    "      <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" + 
    "        <q1:EntityName>account</q1:EntityName>" + 
    "        <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" + 
    "          <q1:Attributes>" + 
    "            <q1:Attribute>accountid</q1:Attribute>" + 
    "            <q1:Attribute>name</q1:Attribute>" + 
    "          </q1:Attributes>" + 
    "        </q1:ColumnSet>" + 
    "        <q1:Distinct>false</q1:Distinct>" + 
    "        <q1:Criteria>" + 
    "          <q1:FilterOperator>And</q1:FilterOperator>" + 
    "          <q1:Conditions>" + 
    "            <q1:Condition>" + 
    "              <q1:AttributeName>accountid</q1:AttributeName>" + 
    "              <q1:Operator>Equal</q1:Operator>" + 
    "              <q1:Values>" + 
    "                <q1:Value xsi:type=\"xsd:string\">" + accountNodeId + "</q1:Value>" + 
    "              </q1:Values>" + 
    "            </q1:Condition>" + 
    "          </q1:Conditions>" + 
    "        </q1:Criteria>" + 
    "      </query>" + 
    "    </RetrieveMultiple>" + 
    "  </soap:Body>" + 
    "</soap:Envelope>" + 
    "";
    
    var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    
    xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
    xmlHttpRequest.send(xml);
    
    var resultXml = xmlHttpRequest.responseXML;
    
    //alert(resultXml);
    
    
    if(resultXml !=null)
    {    
        textReturn= retriveText(resultXml.selectNodes("//BusinessEntity/q1:name"));    
    }
    
    } 
    
     return textReturn;
    }
    


    Tuesday, November 17, 2009 9:29 AM

All replies

  • Hi,

    I don't think so you can achieve this through supported customization (may be i am wrong).

    But using unsupported customization (not recommended) you can achieve this by customizing "convert_to_case.aspx" page. you can write a JS function to get respective account name and can set

    ret.CustomerId = CustomAccountLookup.DataValue[0].id;
    ret.CustomerType = CustomAccountLookup.DataValue[0].type;

    Hope it will help you !!!!


    Mahain
    Tuesday, November 17, 2009 5:06 AM
    Moderator
  • Hi ManikandanJon,

    we have done this requirement using java script code ..in Incident Entity ..Form Load Code...

    following is the code for this..

    please put this code on Case Form On Load Event and enable that event and let me know if there is any issue or problem regarding this..

    //Set Filter for responsible contact to be relevant account
    if(crmForm.all.customerid.DataValue != null)
    {
    
      SetRightCustomer();
    }
    
    function SetRightCustomer()
    {
     // if yes check if it is case
      if(crmForm.all.customerid.DataValue[0] !=null)
      {
        // if customer is selected as contact
        if(crmForm.all.customerid.DataValue[0].typename == "contact")
        {
          //if responsible contactid is not selected then
           if(crmForm.all.responsiblecontactid.DataValue == null)
          {
               ReplaceCustomer(crmForm.all.customerid.DataValue[0].id)       
           }
    
         }
       }
    
    }
    
    
    function ReplaceCustomer(contactId)  
    {  
    
     var xml = "" +  
     "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +  
     "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +  
     GenerateAuthenticationHeader() +  
     " <soap:Body>" +  
     "    <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
    "      <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" + 
    "        <q1:EntityName>contact</q1:EntityName>" + 
    "        <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" + 
    "          <q1:Attributes>" + 
    "            <q1:Attribute>contactid</q1:Attribute>" + 
    "            <q1:Attribute>parentcustomerid</q1:Attribute>" + 
    "          </q1:Attributes>" + 
    "        </q1:ColumnSet>" + 
    "        <q1:Distinct>false</q1:Distinct>" + 
    "        <q1:Criteria>" + 
    "          <q1:FilterOperator>And</q1:FilterOperator>" + 
    "          <q1:Conditions>" + 
    "            <q1:Condition>" + 
    "              <q1:AttributeName>contactid</q1:AttributeName>" + 
    "              <q1:Operator>Equal</q1:Operator>" + 
    "              <q1:Values>" + 
    "                <q1:Value xsi:type=\"xsd:string\">" + contactId+ "</q1:Value>" + 
    "              </q1:Values>" + 
    "            </q1:Condition>" + 
    "          </q1:Conditions>" + 
    "        </q1:Criteria>" + 
    "      </query>" + 
    "    </RetrieveMultiple>" + 
    "  </soap:Body>" + 
    "</soap:Envelope>" + 
    "";
    
    var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    
    xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
    xmlHttpRequest.send(xml);
    
    var resultXml = xmlHttpRequest.responseXML;
    
    //alert(resultXml);
    
    
    
    if(resultXml !=null)
    {    
        var accountId= retriveText(resultXml.selectNodes("//BusinessEntity/q1:parentcustomerid"));     
        if(accountId!="")
        {
              //Create an array to set as the DataValue for the lookup control.     
              var lookupData = new Array(); 
              
             //Create an Object add to the array.     
               var lookupItem= new Object();
          
             //Set the id, typename, and name properties to the object.     
              lookupItem.id = accountId;     
              lookupItem.typename = 'account';    
    
              var lookupname = retriveName(lookupItem.id);     
     
              lookupItem.name = lookupname;
    
             // Add the object to the array.       
              lookupData[0] = lookupItem; 
    
            //Set Responsible Contact from existing customer (as customer is contact)
            crmForm.all.responsiblecontactid.DataValue =  crmForm.all.customerid.DataValue;
    
             // Set the value of the lookup field to the value of the array.           
              crmForm.all.customerid.DataValue = lookupData; 
        
          } 
    
     }
    
    }
    
    
    
    function retriveText(InputNode)
    {
      var text = "";
    
         if (InputNode !=null)
         {
            //alert(InputNode[0].text);
            if(InputNode[0]!=null)
            {
                text =InputNode[0].text;    
            }
         } 
    
     return text;
    }
    
    
    function retriveName(accountNodeId)
    {
      var textReturn = "";
    
         if (accountNodeId!=null)
         {
             var xml = "" +  
     "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +  
     "<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">" +  
     GenerateAuthenticationHeader() +  
     " <soap:Body>" +  
     "    <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" + 
    "      <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" + 
    "        <q1:EntityName>account</q1:EntityName>" + 
    "        <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" + 
    "          <q1:Attributes>" + 
    "            <q1:Attribute>accountid</q1:Attribute>" + 
    "            <q1:Attribute>name</q1:Attribute>" + 
    "          </q1:Attributes>" + 
    "        </q1:ColumnSet>" + 
    "        <q1:Distinct>false</q1:Distinct>" + 
    "        <q1:Criteria>" + 
    "          <q1:FilterOperator>And</q1:FilterOperator>" + 
    "          <q1:Conditions>" + 
    "            <q1:Condition>" + 
    "              <q1:AttributeName>accountid</q1:AttributeName>" + 
    "              <q1:Operator>Equal</q1:Operator>" + 
    "              <q1:Values>" + 
    "                <q1:Value xsi:type=\"xsd:string\">" + accountNodeId + "</q1:Value>" + 
    "              </q1:Values>" + 
    "            </q1:Condition>" + 
    "          </q1:Conditions>" + 
    "        </q1:Criteria>" + 
    "      </query>" + 
    "    </RetrieveMultiple>" + 
    "  </soap:Body>" + 
    "</soap:Envelope>" + 
    "";
    
    var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
    
    xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
    xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/RetrieveMultiple");
    xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
    xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
    xmlHttpRequest.send(xml);
    
    var resultXml = xmlHttpRequest.responseXML;
    
    //alert(resultXml);
    
    
    if(resultXml !=null)
    {    
        textReturn= retriveText(resultXml.selectNodes("//BusinessEntity/q1:name"));    
    }
    
    } 
    
     return textReturn;
    }
    


    Tuesday, November 17, 2009 9:29 AM
  • I'm wondering if you could use a workflow to replace the customer value on Case creation.

    Leon Tribe

    Want to hear me talk about all things CRM? Check out my blog

    http://leontribe.blogspot.com/

    or hear me tweet @leontribe
    Want to hear me talk about all things CRM? Check out my blog http://leontribe.blogspot.com/ or hear me tweet @leontribe
    • Proposed as answer by Leon TribeMVP Sunday, January 17, 2010 8:25 AM
    Sunday, January 17, 2010 8:25 AM