Please write me a client side suitscript 2.0 that ...
# ask-stanley-ai
m
Please write me a client side suitscript 2.0 that when a Sales Order is copied using the action dropdown in the UI, a dialog box appears. When they click OK the script continues to the new copy if cancel, the creation of the copy is stopped.
c
AI generated answer (using internal Slack threads):
Based on the conversations, here is a sample SuiteScript 2.0 client script that will display a dialog box when a Sales Order is copied using the action dropdown in the UI. If the user clicks OK, the script continues to the new copy. If the user clicks Cancel, the creation of the copy is stopped.
Copy code
javascript
/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 */
define(['N/ui/dialog', 'N/currentRecord'], function(dialog, currentRecord) {
    function pageInit(scriptContext) {
        if (scriptContext.mode === 'copy') {
            dialog.confirm({
                title: 'Confirm',
                message: 'Are you sure you want to copy this Sales Order?'
            }).then(function(result) {
                if (!result) {
                    // If the user clicks Cancel, stop the creation of the copy
                    var record = currentRecord.get();
                    record.cancelLine({sublistId: 'item'});
                }
            });
        }
    }

    return {
        pageInit: pageInit
    };
});
This script uses the
pageInit
function to check if the Sales Order is being copied. If it is, it displays a confirmation dialog. If the user clicks Cancel, the
cancelLine
method is used to stop the creation of the copy. ****** 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.86364466
Slack thread 2: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.847966909
Slack thread 3: here (available only if the original thread was posted in the last 90 days)
Similarity score: 0.842260063
Please provide your feedback on this answer.