2012-11-05 100 views
1

海蘭傢伙創建歇電子郵件,如何行與SOAP請求在CRM

我想了幾個小時格式,JavaScript的SOAP請求創建一個電子郵件。但它不會工作,以建立換行符

\n - 不工作 <br /> - 不工作 &#xD; - 不工作 \u000A \u000D - 不工作

這裏是我的電子郵件正文

get_EmailBodyInformManager: function (projectNumber, topic, responsibleDepartment, potentialCustomer, KAMofCustomer, projectManager) { 
    if (KAMofCustomer == null) { 
     KAMofCustomer = ""; 
    } 
    return "Dear Sir or Madam. &#xD;" + 
      "A decision about the project leader for the following international project is necessary: &#xD" + 
      "Project Number: " + projectNumber + "&#xD;" + 
      "Topic: " + topic + " &#xD;" + 
      "Responsible Department: " + responsibleDepartment + "&#xD;" + 
      "Potential Customer: " + potentialCustomer + "&#xD;" + 
      "KAM of Potential Customer: " + KAMofCustomer + "&#xD;" + 
      "WILO Project Manager: " + projectManager + ""; 
}, 

和SOAP請求實際代碼:

 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'>" + 
      authenticationHeader + 
      "<soap:Body>" + 
      "<Create xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>" + 
      "<entity xsi:type='email'>" + 
      "<ownerid>" + userId + "</ownerid>" + 
      "<regardingobjectid type='opportunity'>" + OpportunityId + "</regardingobjectid>" + 
      "<subject>" + subject + "</subject>" + 
      "<description>" + body + "</description>" + 
      "<from>" + 
      "<activityparty>" + 
       "<partyid type='systemuser'>" + userId + "</partyid>" + 
      "</activityparty>" + 
      "</from>" + 
      "</entity>" + 
      "</Create>" + 
      "</soap:Body>" + 
      "</soap:Envelope>"; 
+0

您是否在SOAP請求部分代碼中嘗試過「+」
「+'? –

+0

是的,我曾試過。奇怪的是,
會削減文本,即在
標籤後面。 – ICantSeeSharp

+0

如果我直接將它寫入SOAP請求,則出現錯誤消息「電子郵件實體不包含具有」br「的元素 – ICantSeeSharp

回答

1

應該接受HTML格式,以便只要您通過描述字段通過XML編碼即可。對於您希望通過的數據,我建議將其格式化爲HTML表格,並在每行上顯示內容。我會使用

var description = '<table><tr><td>...</td></tr></table>'; 

寫出來的內容作爲標準的HTML和然後通過這個和其他值,諸如通過下面的函數來對其進行編碼用於通過在XML對象 -

xmlEncode = function(strInput) { 
    var c; 
    var xmlEncode = ''; 

    if (strInput == null) { 
     return null; 
    } 
    if (strInput == '') { 
     return ''; 
    } 

    for (var cnt = 0; cnt < strInput.length; cnt++) { 
     c = strInput.charCodeAt(cnt); 

     if (((c > 96) && (c < 123)) || 
      ((c > 64) && (c < 91)) || 
      (c == 32) || 
      ((c > 47) && (c < 58)) || 
      (c == 46) || 
      (c == 44) || 
      (c == 45) || 
      (c == 95)) { 
      xmlEncode = xmlEncode + String.fromCharCode(c); 
     } else { 
      xmlEncode = xmlEncode + '&#' + c + ';'; 
     } 
    } 

    return xmlEncode; 
} 
+1

It Worked!:)謝謝 – ICantSeeSharp

0

另一種方法即可能更容易實現的是:

  1. 創建一個按需創建電子郵件的工作流程。這將允許您輕鬆編輯和維護模板,例如如果你想改變你不需要重新編碼的電子郵件的措辭。
  2. 從JavaScript開始工作流程。

這將有效地實現與使用JavaScript創建整個電子郵件相同,但可能更容易實現。