locked
Using CrmRestKit to Create a salesorder RRS feed

  • Question

  • Hi All,

    I have an issue about creating a salesorder from an existing one. Im using the CrmRestKit as following:

     var ordernumber = Xrm.Page.getAttribute("ordernumber").getValue();
     var name=Xrm.Page.getAttribute("name").getValue();
     var customerid=Xrm.Page.getAttribute("customerid").getValue();
     var ownerid=Xrm.Page.getAttribute("ownerid").getValue();
     var hli_branchid=Xrm.Page.getAttribute("hli_branchid").getValue();
     var statuscode=Xrm.Page.getAttribute("statuscode").getValue();
     var totallineitemamount=Xrm.Page.getAttribute("totallineitemamount").getValue();
     var discountpercentage=Xrm.Page.getAttribute("discountpercentage").getValue();
     var discountamount=Xrm.Page.getAttribute("discountamount").getValue();
     var totalamountlessfreight=Xrm.Page.getAttribute("totalamountlessfreight").getValue();
     var freightamount=Xrm.Page.getAttribute("freightamount").getValue();
     var totaltax=Xrm.Page.getAttribute("totaltax").getValue();
     var totalamount=Xrm.Page.getAttribute("totalamount").getValue();
     var transactioncurrencyid=Xrm.Page.getAttribute("transactioncurrencyid").getValue();
     var pricelevelid=Xrm.Page.getAttribute("pricelevelid").getValue();

     var prefixBLordernumber = ordernumber.substring(0, 10);
     var RandomNumber = Math.random().toString();
     var ordersufix = RandomNumber.substring(2, 8);

    if (customerid != null)
         var BL_customerid = { Id: customerid[0].id, LogicalName: "account", Name: customerid[0].name };
     else
         BL_customerid = null;
     if (ownerid != null)
         var BL_ownerid = { Id: ownerid[0].id, LogicalName: "systemuser", Name: ownerid[0].name };
     else
         BL_ownerid = null;
     if (hli_branchid != null)
         var BLbranchid = { Id: hli_branchid[0].id, LogicalName: "hli_branch", Name: hli_branchid[0].name };
     else
         BLbranchid = null;
     if (transactioncurrencyid != null)
         var BLtransactioncurrencyid = { Id: transactioncurrencyid[0].id, LogicalName: "transactioncurrency", Name: transactioncurrencyid[0].name };
     else
         BLtransactioncurrencyid = null;
     if (pricelevelid != null)
         var BLpricelevelid = { Id: pricelevelid[0].id, LogicalName: "pricelevel", Name: pricelevelid[0].name };
     else
         BLpricelevelid = null;

     var BLObject = { Name: name,
         CustomerId: BL_customerid, OwnerId: BL_ownerid,
         StatusCode: statuscode,
         TransactionCurrencyId: BLtransactioncurrencyid, PriceLevelId: BLpricelevelid
     };

     

    CrmRestKit.Create('SalesOrder', BLObject, function (result) {
         alert(result);
     });

    The result contain: Error:BadRequest.

    I dont see an error in the tracelog.

    thanks for help

    Thursday, July 14, 2011 1:42 PM

All replies

  • Hello Balhinio,

    what version of the CrmRestKit are you using? Please try this operation with the version 2.4 an set the error-handler. 

    Regards,

    Daniel 

    Tuesday, December 4, 2012 7:11 AM