from a Sales Order id, get the associated invoice ...
# ask-stanley-ai
l
from a Sales Order id, get the associated invoice id through REST api
c
AI generated answer (using internal Slack threads):
To get the associated invoice id from a Sales Order id through REST API, you would need to perform a search operation. Here is a general approach: 1. Use the
GET /record/v1/salesOrder/{id}
endpoint to get the details of the Sales Order. Replace
{id}
with the actual Sales Order id. 2. In the response, look for the
createdFrom
field. This field contains the id of the record (in this case, the Sales Order) that the invoice was created from. 3. Use the
GET /record/v1/invoice
endpoint to get a list of all invoices. 4. Iterate through the list of invoices and match the
createdFrom
field with the Sales Order id. When you find a match, you've found the invoice that was created from the Sales Order. Please note that this is a general approach and might need to be adjusted based on your specific use case and the structure of your data. Here is a sample code snippet in SuiteScript:
Copy code
javascript
var salesOrderId = '123'; // replace with your Sales Order id
var salesOrder = nlapiLoadRecord('salesorder', salesOrderId);
var invoiceId = salesOrder.getFieldValue('createdfrom');

if (invoiceId) {
    var invoice = nlapiLoadRecord('invoice', invoiceId);
    // do something with the invoice
}
****** Disclaimer: This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes. ******
Slack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.814532459
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.813039303
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.81096518
Please provide your feedback on this answer.
Thank you for your feedback
l
Wrong order of relationship, this is to get the Sales Order from an Invoice, I want to get the Invoice from the sales order