1

长话短说,当我将 URL 结尾更改为“AccountSet”时,此代码将创建一个帐户,但当我尝试创建新机会时,它只会给我一个“错误请求”错误。有人看到我缺少的东西吗?非常感谢您在这里提供的任何帮助。(另外,作为记录,我确实尝试了 CRMRestkit,但也出现了错误)。

var newOpportunity = new Object();

newOpportunity.Name = "TEST";
newOpportunity.StatusCode = 0;

var contact = new Object();
contact.Id = "b4531ee9-9477-4262-8e18-00b60369352a";
contact.LogicalName = "contact";
contact.Name = "Bacon Jones";

newOpportunity.ContactId = contact;

var jsonNewOpp = window.JSON.stringify(newOpportunity);

$.ajax({ type: "POST",
    contentType: "application/json; charset=utf-8",
    datatype: "json",
    url: Xrm.Page.context.getServerUrl() + "/XRMServices/2011/OrganizationData.svc/OpportunitySet",
    data: jsonNewOpp,
    beforeSend: function (XMLHttpRequest) {
        XMLHttpRequest.setRequestHeader("Accept", "application/json");
    },
    success: function (data, textStatus, XmlHttpRequest) {
        alert("success");
        //var getNewRecord = data["d"];
        //alert("GUID: " + getNewRecord.OpportunityId);
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {
        alert("failure due to " + errorThrown);
    }
});
4

1 回答 1

0

您是否尝试过运行 Fiddler 以接收更好的错误消息?

代码看起来不错,也许错误出在字段名称中?

REST 端点是否抛出相同的错误?

谢谢,

马里奥

于 2013-07-08T09:23:50.447 回答