How to assign Terms of payment to an Invoice via Suitescript or API?

How can I assign Terms of payment to an Invoice via suitescript (or any other programmatic means, e.g. API)? I haven’t been able to locate examples/documentation of that.

Rookie Asked on February 2, 2023 in How To's.
Add Comment
5 Answer(s)

Hi,

Both of these are possible but are very different solutions.

Could you please explain your use case in more detail.

Thanks,

Chris

Intermediate Answered on February 2, 2023.
Add Comment

The first use-case I have in mind: in order to introduce payment terms to an organization that was not previously using them, I’ll need to update Terms of payment on a large list of existing Customers.

The second use-case is assigning specific on invoices that are automatically created by a workflow that transforms Sales Orders. Actually, this might not be necessary, since the invoice should default to whatever Terms have been set on the Customer (according to the docs).

Rookie Answered on February 2, 2023.
Add Comment

Hi,

In that case, we’re just left with the first scenario. Have you considered Mass Update for this rather than having to build something?

Thanks,

Chris

Intermediate Answered on February 3, 2023.
Add Comment

It sounds like Mass Update would solve it in many cases. However, it’s possible the criteria for which Customers should be included in the update will be beyond the capabilities of that tool, so I may be presented with a (huge) list of IDs and need to update the corresponding Customers. It would be very helpful to see an example of how I could script that kind of operation.

Rookie Answered on February 3, 2023.
Add Comment

To assign Terms of Payment to an invoice in NetSuite using SuiteScript or the API, you can follow the steps below:

Using SuiteScript:
1. Create a new SuiteScript or open an existing script deployment in NetSuite.
2. Write code to load the invoice record you want to update. This can be done using `nlapiLoadRecord` or `record.load` function depending on the SuiteScript version you are using.
3. Set the Terms field on the invoice record to the desired Terms of Payment. This can be done using the `setValue` or `setValue` function. The field ID for the Terms field is typically `terms`.
4. Save the changes to the invoice record using the `record.save` or `nlapiSubmitRecord` function.

Here’s an example SuiteScript 2.0 code snippet that assigns Terms of Payment to an invoice:

“`javascript
/**
* Example SuiteScript 2.0 code to assign Terms to an invoice
*/

function assignTermsToInvoice(invoiceId, termsId) {
var invoiceRecord = record.load({
type: record.Type.INVOICE,
id: invoiceId,
isDynamic: true
});

invoiceRecord.setValue({
fieldId: ‘terms’,
value: termsId
});

invoiceRecord.save();
}
“`

Replace `invoiceId` with the internal ID of the invoice record you want to update, and `termsId` with the internal ID of the desired Terms of Payment record.

Using API:
If you prefer using the NetSuite API, you can achieve the same result by making a request to the `PUT` endpoint for the Invoice resource (`/record/v1/invoice/:id`), specifying the Terms field in the payload.

Here’s an example using cURL:

“`shell
curl -X PUT \
-H “Authorization: Bearer YOUR_ACCESS_TOKEN” \
-H “Content-Type: application/json” \
-d ‘{
“fields”: {
“terms”: YOUR_TERMS_ID
}
}’ \
https://<YOUR_ACCOUNT_ID>.suitetalk.api.netsuite.com/services/rest/record/v1/invoice/:id
“`

Replace `YOUR_ACCESS_TOKEN` with your actual access token, `<YOUR_ACCOUNT_ID>` with your NetSuite account ID, `YOUR_TERMS_ID` with the internal ID of the desired Terms of Payment record, and `:id` with the internal ID of the invoice you want to update.

Remember to refer to the NetSuite SuiteScript or API documentation for further details on available functions, field IDs, and payload structures based on your specific NetSuite version and integration requirements.

Rookie Answered on May 17, 2023.
Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.
  • This site made possible by our sponsors:   Tipalti   Celigo   Limebox   Become a Sponsor   Become a Sponsor