Is there any documentation of a working ClientScri...
# suitescript
n
Is there any documentation of a working ClientScript
ValidateField
function that shows a modal. Example, Field value cannot be less than 0, When a user enters -1 a Modal appears informing them "Cannot be less than 0"
Copy code
if(valid){
    return true;
}else {
    dialogModule.create({
        title: 'Invalid Amount',
        message: 'Cannot be less than 0'
    });
    return false;
}
This code just spawns infinite Dialogs
Figured it out...
m
Was this a sublist field?
m
@nathanw How did you resolve this? I've had issues with the infinite loop of dialogs with this sort of validation structure and it drives me nuts - I'd love to know if there's a way to functionally combine
N/ui/dialog
and returning
false
in
validateField
without causing issues. My current workaround is to clear out the field that fails validation so it doesn't keep failing but that's not great UX.
n
@michoel It was not.
@MTNathan Here is what I ended up with.
Copy code
if (valid) {
    return true;
} else {
    function zeroOut(scriptContext) {
        currentRecordModule.get().setValue({
            fieldId: 'discountrate',
            value: 0,
            ignoreFieldChange: false,
            forceSyncSourcing: true
        });
    }
    dialogModule.alert({
        title: 'Invalid Discount Percent or Amount',
        message: 'Invalid Discount Percent or Amount. Must be less than 20%'
    }).then(zeroOut).catch(zeroOut);
    return true;
}
I admit it's not correct, no point in calling
zeroOut
in both the
.then
and the
.catch
and I could have messed with the
ignoreFieldChange
some, The Essential part is that you have to return
true
or infinite loop.
m
Gotcha, sounds like the same end result of what I'm doing - if it fails validation, force it to pass validation alongside the
dialog.alert
to avoid an infinite loop. Rather frustrating since that could just as effectively be done as the first thing in the
fieldChanged
entry point and the user doesn't get the benefit of modifying their entry (as opposed to starting from scratch), but if that's what works, I guess it's our best option for now. Thanks for responding!