Jared Fraley
04/21/2025, 6:03 PMCeligo AI
04/21/2025, 6:03 PMAI generated answer (using internal Slack threads):To add a markup line item on a sales order and set the rate to be a percentage rather than a flat value with SuiteScript, you can use the
setText
method for percentage and setValue
for flat rate. However, it's important to note that the timing of when you try to get values matters since SuiteScript methods are asynchronous in client scripts.
Here is a sample code snippet that you can modify according to your needs:
javascript
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
* @NModuleScope SameAccount
*/
define(['N/currentRecord', 'N/log', 'N/search'],
function(currentRecord, log, search) {
function fieldChanged(context) {
var record = context.currentRecord;
if (context.fieldId == 'quantity' || context.fieldId == 'item') {
var _rate = parseInt(record.getCurrentSublistValue("item", "rate"));
alert ('rate=' + _rate);
} //if (context.fieldId == 'item') {
}
return {
fieldChanged: fieldChanged
};
});
In this script, the fieldChanged
function is triggered when the 'quantity' or 'item' field is changed. It then gets the current rate of the item and alerts it. You can replace the alert with your logic to set the rate as a percentage.
Remember, if you're getting a USER_ERROR stating "please enter value for amount", it might be because you're trying to set the rate and amount at the same time. Try setting only the rate and see if that resolves the issue.
******
Disclaimer:
This response was generated by an artificial intelligence assistant based on previous conversations from multiple Slack channels, and may contain inaccuracies or mistakes.
******Celigo AI
04/21/2025, 6:03 PMSlack thread 1: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.861324251
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.8550089
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.841752827
Celigo AI
04/21/2025, 6:03 PM