Hello, I am working on a client script which valid...
# suitescript
k
Hello, I am working on a client script which validates a field in the Item sublist on a Sales Order record. If the validation fails, I want to throw a dialog asking the user to correct the value in that field. below is a snippet:
Copy code
if (sublistName === 'item') {
    if (sublistFieldName === 'custcol_start_date') {
        var start_date = currentRecord.getCurrentSublistValue({
            sublistId: sublistName,
            fieldId: sublistFieldName
        });

        var end_date = currentRecord.getSublistValue({
            sublistId: sublistName,
            line: line,
            fieldId: 'custcol_end_date'
        });

        if(!moment(start_date).isSameOrBefore(end_date)){
            
            dialog.alert({
                title: 'Start Date can not be after End date',
                message: 'Click OK to continue.'
            })

            return false;
        }
    }
}

return true;
When I deploy this code, the validation works and the dialog appears, but when I click OK on the dialog box, nothing happens and the screen kind of freezes there. What am I missing here? Is using a dialog box in this scenario not a good idea?
b
your code doesnt do anything else
it shows the dialog and returns false
what did you want to occur when ok is pressed
k
ohh, I want to wipe out the value in the field and have the enter the correct value
b
you need to code that behavior
k
where would that behavior be in this code?
b
use setValue
k
I added the following after the dialog, but nothing happens. even the dialog does not appear now. this is a date field btw
Copy code
currentRecord.setCurrentSublistValue({
                                    sublistId: sublistName,
                                    fieldId: 'custcol_start_date',
                                    line: line,
                                    value: null
                                });