how to creat a custom transaction body field that ...
# ask-stanley-ai
n
how to creat a custom transaction body field that sums/totals the amount of an Item Receipt. This Receipt Total is then displayed on the Item Receipt screen. in netsuite
c
AI generated answer (using internal Slack threads):
To create a custom transaction body field that sums/totals the amount of an Item Receipt and display it on the Item Receipt screen in NetSuite, you can follow these steps: 1. Create a User Event (UE) script that will be triggered on the beforeSubmit event of the Item Receipt. This script will iterate over the line items in the Item Receipt, summing the amounts. 2. In the script, use the
record.getCurrentSublistValue({sublistId: 'item', fieldId: 'amount'})
function to get the amount of each line item. Accumulate these amounts in a variable. 3. After summing all the line items, use the
record.setValue({fieldId: 'custbody_your_custom_field', value: totalAmount})
function to set the value of your custom transaction body field to the total amount. 4. Deploy the script and associate it with the Item Receipt record type. Here is a sample code snippet for the User Event script:
Copy code
javascript
/**
 * @NApiVersion 2.x
 * @NScriptType UserEventScript
 */
define(['N/record', 'N/search'], function(record, search) {
    function beforeSubmit(context) {
        if (context.type !== context.UserEventType.CREATE && context.type !== context.UserEventType.EDIT) {
            return;
        }
        var rec = context.newRecord;
        var lineCount = rec.getLineCount({sublistId: 'item'});
        var totalAmount = 0;
        for (var i = 0; i < lineCount; i++) {
            var lineAmount = rec.getSublistValue({sublistId: 'item', fieldId: 'amount', line: i});
            totalAmount += lineAmount;
        }
        rec.setValue({fieldId: 'custbody_your_custom_field', value: totalAmount});
    }
    return {
        beforeSubmit: beforeSubmit
    };
});
Please replace
'custbody_your_custom_field'
with the actual ID of your custom transaction body field. ****** 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.843078613
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.838439941
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.829467773
Please provide your feedback on this answer.
a
There is already total field on header of any transaction. if you want to add of your own by any other logic. you can do it by script