When I create an invoice with xrm.ConvertSalesOrderToInvoice(), the invoice total is zero. How do I force the invoice total to match the sales order total? RRS feed

  • Question

  • I'm using the CRM 2015 Portal SDK (Microsoft.CrmSdk.Extensions 7.1.0 from NuGet), and trying to create an invoice based on an existing sales order. Here's the code I'm running - this is inside an Action method in an ASP.NET MVC 5 project:

    public ActionResult CreateInvoice(Guid id) {
      var xrm = new SpotlightXrmServiceContext("ConnectionStrings.Crm2015.Spotlight");
      var order = xrm.SalesOrderSet.FirstOrDefault(o => o.Id == id);
      var columns = new ColumnSet(true);
      var invoiceEntity = xrm.ConvertSalesOrderToInvoice(order.Id, columns);

    After running this code, the Invoice exists in the CRM database, and I can see it listed in the CRM UI by navigating to Sales > Invoices - but the invoice total is zero. If I click the invoice in the CRM UI to view it, something behind the scenes forces a recalculation, because when the invoice loads, the total is £154 (which is the total amount of the original sales order)

    The web app in question is a post-payment redirect from our payment provider, so what I need to do from my web application is:

    1. Locate the existing sales order
    2. Create an invoice associated with that order
    3. Mark the invoice as Paid
    4. Mark the sales order as fulfilled

    and I appear to have fallen at the first hurdle. Any ideas?



    Monday, September 21, 2015 11:09 AM