i have a fields in a custom sublist i want that wh...
# ask-stanley-ai
n
i have a fields in a custom sublist i want that when there are values in both fields i calculate the multiplication of these fields and set them in a third field in netsuite
c
AI generated answer (using internal Slack threads):
Based on the conversations, you can achieve the multiplication of two fields and setting the result in a third field using SuiteScript. You can use a Client Script and the
fieldChanged
event to perform the calculation whenever the values of the two fields are changed. Here is a sample code snippet:
Copy code
javascript
define(['N/record','N/search','N/ui/dialog', 'N/log'], function (record, search, dialog, log) {
    /**
    *@NApiVersion 2.0
    *@NScriptType ClientScript
    */
   
    function fieldChanged(context) {
        var currentRecord = context.currentRecord;
           
        if(context.fieldId == "field1" || context.fieldId == "field2") {
            var field1 = currentRecord.getValue({
                fieldId: 'field1'
            });
            console.log(field1);

            var field2 = currentRecord.getValue({
                fieldId: 'field2'
            });
            console.log(field2);

            var result = field1 * field2;
            console.log(result);

            if (field1 && field2) {
                currentRecord.setValue({
                    fieldId: 'field3',
                    value: result,
                    ignoreFieldChange:true
                });
            }    
        }
    }
   
    return {
        fieldChanged: fieldChanged
    };
});
In this script, replace
field1
,
field2
, and
field3
with the actual field IDs of your custom sublist. This script will trigger every time there is a change in
field1
or
field2
, calculate the multiplication of
field1
and
field2
, and set the result in
field3
. ****** 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.854231596
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.840154886
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.836543262
Please provide your feedback on this answer.