简体   繁体   中英

CRM 2011, Creating SalesOrderDetail with JavaScript

I'm having some trouble creating a salesorderdetail with JavaScript in CRM 2011 from a WebResource.

I have tried using XrmServiceToolkit (both rest and soap) and also just with jquery. They all fail and the error messages I get don't really point me in a direction that makes much sense.

For the record I'm using XrmServiceToolkit to retrieve and create other places in my code with no problems.

I'm starting to think that I'm either missing some required attribute or that something is just formatted incorrect and that the server fails to point that out in the error message.

Here is an example of the last request I sent (when using jquery):

    {
  "SalesOrderId":{
    "Id":"83b09bc4-162a-e511-9a7b-00155d39be02",
    "LogicalName":"salesorder"
  },
  "ProductId":{
    "Id":"dd194def-5756-e211-89c3-00155d19380e",
    "LogicalName":"product"
  },
  "PricePerUnit":{
    "Value":"0.00000"
  },
  "Description":"",
  "BaseAmount":{
    "Value":"0.00000"
  },
  "ManualDiscountAmount":{
    "Value":"0.00000"
  },
  "ExtendedAmount":{
    "Value":"0.00000"
  },
  "LineItemNumber":4,
  "Quantity":{
    "Value":"1.00000"
  },
  "TransactionCurrencyId":{
    "Id":"1f9b9e82-91fc-df11-b612-00155d193722",
    "LogicalName":"transactioncurrency"
  },
  "UoMId":{
    "Id":"79b6977d-a2af-42a0-8497-1a0238d629ac",
    "LogicalName":"uom"
  },
  "OwnerId":{
    "Id":"96a0f8e0-2ef7-e111-bfff-00155d19380e",
    "LogicalName":"systemuser"
  }
}

There used to be a date attribute as well, but I took it out to make sure it wasn't the cause.

I'm sending it request like this (when using jquery):

$.ajax({
        type: "POST",
        contentType: "application/json; charset=utf-8",
        datatype: "json",
        url: odata_endpoint +"/SalesOrderDetailSet",
        data: JSON.stringify(object),
        beforeSend: function (XMLHttpRequest)
        {
            XMLHttpRequest.setRequestHeader("Accept", "application/json");
        },
        success: function (data, textStatus, XmlHttpRequest)
        {
            var created_record = data["d"];

            console.log("create success: " + JSON.stringify(created_record));
        },
        error: function (XmlHttpRequest, textStatus, errorThrown)
        {
            console.log("create failed: " + JSON.stringify(errorThrown));
        }
    });

In this case I'm getting this error: Incorrect attribute value type System.Data.Services.Serializers.JsonReader+JsonObjectRecords.

I cannot get my head around why this keeps failing, so if anyone could throw some fresh eyes at this it would be much appreciated, thanks.

I believe it is related to Quantity field. Quantity is decimal so you should use

Quantity: "1.0000"

instead of

  "Quantity":{
    "Value":"1.00000"
  },

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM