Trying to add a new line with a client script. Wit...
# suitescript
i
Trying to add a new line with a client script. With the new line that I add I use commitLine, but it doesn't actually add the line. Is there a way for the user to not have to click the add button?
b
More code required
i
..? What do you mean?
b
Share your code
Without your code, my guess is that you should use forceSyncSourcing
i
Copy code
/**
 *
 *@NApiVersion 2.x
 *@NScriptType ClientScript
 */

define(['N/ui/dialog'], function (dialog) {

    function saveRecord(context) {
        var options = {
            title: 'Restocking Fee',
            message: 'Would you like to add a restocking fee?',
            buttons: [
                {
                    label: 'Yes',
                    value: 1
                },
                {
                    label: 'No',
                    value: 2
                }]
        };

        function success(result) {
            console.log('Success: ' + result);

            var currentRecord = context.currentRecord;

            if (result == 1) {
                currentRecord.selectNewLine({
                    sublistId: 'item'
                });

                currentRecord.setCurrentSublistValue({
                    sublistId: 'item',
                    fieldId: 'item',
                    value: 947
                });

                currentRecord.commitLine({
                    sublistId: 'item'
                });

                currentRecord.selectNewLine({
                    sublistId: 'item'
                });

            }


            return true;
        }

        function failure(reason) {
            console.log('Failure: ' + reason)
        }

        dialog.create(options).then(success).catch(failure);
    }

    return {
        saveRecord: saveRecord
    }
});
@battk
That worked. Thanks!