RE: 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.

ibrennan Rookie Asked on February 2, 2023 in How To's.
Add Comment
5 Answers

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.