【问题标题】:getting an error Object doesn't support property or method 'setSrc' in web Resource in CRM 2011收到错误对象不支持 CRM 2011 中 Web 资源中的属性或方法“setSrc”
【发布时间】:2013-04-06 06:24:22
【问题描述】:

我在页面上使用了 WebResource,但我收到一个错误 Object does not support property or method 'setSrc' in Javascript

你能帮帮我吗

我的实际代码是这样的

function getImage()
{
var entityId = Xrm.Page.data.entity.getId();
var profilePictureElement = Xrm.Page.getControl("WebResource_ProfilePicture");
if (entityId) {
    var oDataQuery = getServerUrl() + "/XRMServices/2011/OrganizationData.svc" +
        "/AnnotationSet?$top=1&$select=AnnotationId,DocumentBody,MimeType&" +
        "$orderby=ModifiedOn desc&$filter=ObjectId/Id eq guid'" + entityId +
        "' and IsDocument eq true and Subject eq 'Profile Picture'" +
        " and startswith(MimeType,'image/') ";

    $.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: oDataQuery,
        beforeSend: function (request) { request.setRequestHeader("Accept", "application/json"); },
        success: function (data, textStatus, request) {
            if (data.d.results.length > 0) {
                var mimeType = data.d.results[0].MimeType;
                var body = data.d.results[0].DocumentBody;
                // set src attribute of default profile picture web resource.
                // here we use DataURI schema which has 32kb limit in IE8 and doesn't support IE <= 7.
                profilePictureElement.setSrc("data:" + mimeType + ";base64," + body);

            }
        },
        error: function (request, status, exception) { }
    });
  }
}
function getServerUrl()
{
var serverUrl = Xrm.Page.context.getServerUrl();
// trim trailing forward slash in url
return serverUrl.replace(/\/*$/, "");
}

你可以参考这里的整篇文章http://blogs.msdn.com/b/crm/archive/2011/09/28/displaying-a-contact-s-facebook-picture-in-microsoft-dynamics-crm-2011.aspx?CommentPosted=true#commentmessage

【问题讨论】:

  • 嗨@Kartik检查profilePictureElement的值
  • Pedro Azevedo :我检查了它的值,并且我在 profilePictureElement 中正确获取了网络资源,但不知道为什么会这样?
  • 你怎么知道你得到了正确的?
  • @James Wood:使用调试器..

标签: javascript dynamics-crm-2011 dynamics-crm crm onload


【解决方案1】:

现在看来,getSrcsetSrc 方法只能在引用 HTML 内容时用于 Web 资源。

如果网络资源是图片,crm 将使用img 标签来显示图片。

如果您想让该代码正常工作,您需要检索 img 元素并手动分配 src 属性:

而不是

profilePictureElement.setSrc("data:" + mimeType + ";base64," + body);

你需要写

var profilePicture = document.getElementById("WebResource_ProfilePicture");
profilePicture.setAttribute("src","data:" + mimeType + ";base64," + body);

注意:这是不受支持的自定义

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-04-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-31
    • 2011-08-25
    相关资源
    最近更新 更多