Hi all, I'm coming up against a bug that I can't s...
# suitescript
a
Hi all, I'm coming up against a bug that I can't see to solve so I'm wondering if anyone has any insight. I recently deployed a ClientSide Script that runs on "Validate Line" when a new item is added to a sales order. It checks to see if either a location is chosen or if the item is a drop ship item and if neither are chose it displays a native JS alert, alerting the user to choose one. The problem that we're running into is that for some reason multi-line shipping is no longer working. Is there a way to specify that the script should only run when adding items under the item tab?
Below is a sample of my code.
Copy code
/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 */

define(
    [
        'N/currentRecord'
    ],
    function (
        currentRecord
    ) {
        function validateLine(context) {
            var salesOrder = currentRecord.get();
            console.log('Confirm Line Items');
            if (context.sublistId == 'item') {
                var itemType = salesOrder.getCurrentSublistValue({
                    sublistId: 'item',
                    fieldId: 'itemtype'
                });

                var createPO = salesOrder.getCurrentSublistValue({
                    sublistId: 'item',
                    fieldId: 'createpo'
                });

                var location = salesOrder.getCurrentSublistValue({
                    sublistId: 'item',
                    fieldId: 'location'
                });
                console.log('Item Type' + itemType);
                console.log('Create PO' + createPO);
                console.log('Location' + location);

                if (!createPO && !location && (itemType == "NonInvtPart" || itemType == "InvtPart")) {
                    alert('This item is missing a location or dropship purchase order.' +
                        '\nPlease confirm that you would like to continue.');
                }
                return true;
            }
        }

                return {
            validateLine: validateLine
        };
    }
);
s
Since its a validate script, you need to return true outside your if as well
If you are never going to reject/return false, validate is probably not the correct entry point.
Also
var salesOrder = currentRecord.get()
should probably be changed to
context.currentRecord;
a
Got it, thank you so much.
Following up with your other point. If I want the script to check the criteria for each line as it's added, what be the recommended entry point?
s
If you want to check criteria as the line is added, then validate is the correct entry point. However, in your code, you are only ever returning true, which means you are not really validating.
a
True, the idea is just to alert the user of the error but they can still choose to continue. We do want it to run as each line is being committed. Is there another way to do this?
s
I believe
sublistChanged
could work as well, there is nothing wrong with using validateLine and always
return true
at the end, just make sure you do that
a
@Sandii Got it, thanks so much for your help.