1

嗨伙计们,

我正在尝试几个小时来格式化使用 JavaScript 和肥皂请求创建的电子邮件。但是设置换行符不起作用

\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 + "";
},

和肥皂请求:

        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>";
4

2 回答 2

1

只要您通过描述字段传递的内容是为 XML 编码的,它就应该接受 HTML 格式。对于您要传递的数据,我建议将其格式化为 HTML 表格,内容显示在每一行。我会使用标准的 HTML 写出内容

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

然后通过以下函数传递 this 和其他值(例如主题)以对其进行编码以传递 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;
}
于 2012-11-05T19:44:58.317 回答
0

另一种可能更容易实施的方法是:

  1. 创建创建电子邮件的按需工作流。这将允许您轻松地编辑和维护模板,例如,如果您想更改电子邮件的措辞,您将不必重新编码。
  2. 从 JavaScript 启动工作流。

这将有效地实现与在 JavaScript 中创建整个电子邮件相同的效果,但可能更容易实现。

于 2012-11-06T09:24:08.680 回答