To take a subset of data from the Sales Order and save it in a Custom Body Field on Sales Order SuiteScript 2.0, you can use the following steps:
Create a custom field on the Sales Order record to store the subset of data.
Create a SuiteScript 2.0 script that will retrieve the desired data from the Sales Order record and store it in the custom field.
In the script, use the N/record
module to load the Sales Order record.
Use the N/search
module to perform a search for the desired data.
Use the getValue()
method to retrieve the value of the desired field on the Sales Order record.
Use the setValue()
method to set the value of the custom field with the retrieved data.
Save the Sales Order record.
Here's an example of what the script could look like:
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
* @NModuleScope SameAccount
*/
define(['N/search', 'N/record'],
function(search, record) {
function afterSubmit(context) {
if (context.type === context.UserEventType.CREATE ||
context.type === context.UserEventType.EDIT) {
var salesOrderId = context.newRecord.id;
// Load the Sales Order record
var salesOrder = record.load({ type: record.Type.SALES_ORDER, id: salesOrderId });
// Perform a search for the desired data
var searchResults = search.create({
type: search.Type.SALES_ORDER,
filters: [ ['internalid', 'anyof', salesOrderId] ],
columns: [ 'total' ]
}).run().getRange({ start: 0, end: 1 });
if (searchResults.length > 0) {
var total = searchResults[0].getValue('total');
// Set the value of the custom field with the retrieved data
salesOrder.setValue({ fieldId: 'custbody_sales_order_total', value: total });
// Save the Sales Order record
salesOrder.save();
}
}
}
return {
afterSubmit: afterSubmit
};
});
In the example above, the script sets the value of a custom field called custbody_sales_order_total
with the total amount of the Sales Order. The script performs a search for the Sales Order using its internal ID, gets the total amount, and sets the value of the custom field on the Sales Order record. The script then saves the Sales Order record. You can modify the script to retrieve and store different subsets of data as needed.
Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss
Asked: 2021-06-13 11:00:00 +0000
Seen: 8 times
Last updated: May 16 '22
How can one obtain live data from interactive broker through API?
What is the method to implement pagination for Firestore data in Flutter using ListView?
What is the reason for the submitted Django form's value being null in the database?
How can we create summary tables by using nested tibbles?
What is the process of moving information from one tab to another in Excel by transposing it?
What does "coxphw undefined columns selected" mean?
Is it not possible to change the data type of an array from 'O' to 'float64'?
How to perform a historical backfill from GA4 into BigQuery?
How can Redux be integrated with Ag-Grid's server-side row model in React?