Search code examples
netsuitesuitescript

Applying logic to button Make Copy - Netsuite


I just started with Netsuite and Suitescript 2.1. I am wondering if I can apply any logic to the "Make Copy" button via suitescript. The make copy button is on the opportunity > sublist Item > Line item. Examples of what I want to do:

  • Reset certain fields of the copied line
  • Fill in certain fields of the copied line (with a certain logic behind it)

enter image description here


Solution

  • I already found a solution. I use the validateLine function. When making a copy of a lineitem in Netsuite the lineitem field: "line" has an empty string value until the line is created by clicking the "Add" button or clicking outside of the copied lineitem. I will check if that field is empty, if yes it means the line is a copy. Afterwards I can also set a custom field isCopy = true.

           const lineIsCopied = () => {
                let lineNumber = opportunity.getCurrentSublistValue({
                    sublistId: 'item',
                    fieldId: 'line'
                });
    
                if (lineNumber) {
                    //linenumber is existing this means line is not a copy
                    return false;
                } else {
                    //linenumber is empty this mean line is a copy
                    return true;
                }
            };