Javascript 获取错误对象不需要';t支持属性或方法';setSrc';CRM 2011中的网络资源

Javascript 获取错误对象不需要';t支持属性或方法';setSrc';CRM 2011中的网络资源,javascript,dynamics-crm-2011,dynamics-crm,crm,onload,Javascript,Dynamics Crm 2011,Dynamics Crm,Crm,Onload,我已经在页面上使用了WebResource,我得到一个错误对象不支持Javascript中的属性或方法“setSrc” 你能帮帮我吗 我的实际代码是这样的 function getImage() { var entityId = Xrm.Page.data.entity.getId(); var profilePictureElement = Xrm.Page.getControl("WebResource_ProfilePicture"); if (entityId) { var oD

我已经在页面上使用了WebResource,我得到一个错误对象不支持Javascript中的属性或方法“setSrc”

你能帮帮我吗

我的实际代码是这样的

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(/\/*$/, "");
}
函数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+ “'IsDocument eq true和Subject eq'Profile Picture'”+ “并开始使用(MimeType,'image/”)”; $.ajax({ 键入:“获取”, contentType:“应用程序/json;字符集=utf-8”, 数据类型:“json”, url:oDataQuery, beforeSend:function(request){request.setRequestHeader(“Accept”,“application/json”);}, 成功:功能(数据、文本状态、请求){ 如果(data.d.results.length>0){ var mimeType=data.d.results[0].mimeType; var body=data.d.results[0].DocumentBody; //设置默认配置文件图片web资源的src属性。
//这里我们使用的DataURI模式在IE8中有32kb的限制,不支持IE看起来像现在的方法
getSrc
setSrc
只能在引用HTML内容时对Web资源使用

如果Web资源是图像,crm将使用
img
标记来显示图片

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

而不是

你需要写作

var profilePicture=document.getElementById(“WebResource_profilePicture”);
setAttribute(“src”,“data:+mimeType+”;“base64”,+body);

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

您好@Kartik检查profilePictureElementPedro Azevedo的值:我已经检查了它的值,并且在profilePictureElement中正确获取了webresource,但不知道为什么会发生这种情况?您如何知道正确获取了它?@James Wood:使用调试器。。
profilePictureElement.setSrc("data:" + mimeType + ";base64," + body);