0

I am not able to set "Created From" on Invoice to reference a Sales Order record through the SOAP web service. I have tried setting this field directly and also through Initialize API (initializing a invoice record using the sales order and then copying the CreatedFrom field from the initialized invoice to the invoice being created).

I don't get any errors yet the Created From field doesn't get set on the created invoice record.

The code I am trying looks something like this:

// initialize invoice from sales order
var initializeRecord = new InitializeRecord()
            {
                type = InitializeType.invoice,
                reference = new InitializeRef() { internalId = "sales-order-internal-id", type = InitializeRefType.salesOrder, typeSpecified = true }
            };            
            var result = Utility.Do(async () => await connector.NetSuiteClient.initializeAsync(initializeRecord));
SuiteTalk.Invoice initializedInvoice = result.record;

// create a invoice and copy over the "createdFrom" field
var invoice = new SuiteTalk.Invoice();
invoice.createdFrom = initializedInvoice.createdFrom;

/* set other fields on the invoice and add some line items
....
...
..
*/

// finally create the invoice
var result = Utility.Do(async () => await connector.NetSuiteClient.addAsync(invoice));

How I can associate this invoice to a sales order while creating it?

Heretic Monkey
  • 11,687
  • 7
  • 53
  • 122
Vinay
  • 1
  • Transform the sales order into an Invoice. See the help topic: `record.transform(options)`. However adding lines etc might be problematic as you will be trying to invoice things you didn't sell. – Brian Jan 05 '21 at 19:40
  • Thanks @Brian for your response. The transform record seems to be a WF action. I am trying to do this through the Web Service and InitializeRecord function seems to be the equivalent for transform which is not working for me. – Vinay Jan 06 '21 at 13:24

2 Answers2

1

What you will have to do -- as painful as it is -- is to use the transformed record provided to you by netsuite from the initializeRecord call, and then modify it. It is a pain because there are several fields that you will have to unset as you fill in the record.

The issue is that there are createdFrom associations on both the header level, and the line level, that need to be filled in for the sales order to invoice association to take.

here are the list of line fields that I had to unset in the invoice:

line-level:

  • quantityRemaining
  • quantityAvailable
  • quantityFulfilled
  • quantityOrdered
  • quantityOnHand
  • costEstimate
  • taxRate1

here are the header-level fields:

  • subTotal
  • total
  • totalCostEstimate
  • estGrossProfit
  • estGrossProfitPercent
  • discountTotal
  • giftCertApplied
  • shippingTax1Rate
2ps
  • 15,099
  • 2
  • 27
  • 47
  • Thanks, that makes sense. Let me try it out – Vinay Jan 12 '21 at 07:30
  • In my case, I had to reset some more fields to get it to work. I only went down that path due to your suggestion so thanks again for that! – Vinay Jan 15 '21 at 16:19
  • The fields were altShippingCost, exchangeRate & salesTeamList on the invoice body. – Vinay Jan 15 '21 at 16:28
0

Thank you 2ps. In my case this code was enough

Invoice invoice = (Invoice)initializeResponse.record;
                    invoice.totalCostEstimateSpecified = false;
                    invoice.estGrossProfitPercentSpecified = false;
                    invoice.discountTotalSpecified = false;
                    invoice.totalSpecified = false;

                    foreach (var item in invoice.itemList?.item)
                    {
                        item.quantityRemainingSpecified = false;
                        item.costEstimateSpecified = false;
                    }

                    var writeResponse = svc2.add(invoice);