When validating a field change, can you get the pr...
# suitescript
s
When validating a field change, can you get the previous value from a client script? Also, how on earth do you alert() in the validateField without an infinite amount of alerts lol
c
You could load the record and keep it in a global and use that to compare values.
s
That's what I did. Still lame. I also wish I could validate it and pop up an alert lol
c
Why can't you validate and pop an alert?
s
it goes on an infinite loop if I return false
Every time I click ok it triggers validateField
c
it shouldn't fire validateField until you click out of it
s
That's what I think too. But when I added the alert, infinite loop
c
are you returning true/false correctly?
sounds like maybe you have that backwards or something
s
Yeah. it only returns false if it gets to the alert
c
whats your code look like?
s
Copy code
let isValid = true;
const rec = ctx.currentRecord;
const tranId = rec.getValue('tranid');
if (_tranId === tranId) {
    return true;
} else {
    let splitNewTranId = tranId.split('-');
    let splitTranId = _tranId.split('-');

    for (let i in splitTranId) {
        let tranId = splitTranId[i];
        if (!isNaN(tranId)) {
            const results = tranId === splitNewTranId[i];
            if (!results) {
                isValid = false;
                break;
            }
        } else if (tranId !== 'SO' || tranId !== '-P' || tranId !== '-N') {
            isValid = false;
            break;
        }
    }
}
if (!isValid) {
    alert(`'The Order # is Invalid and only accepts -P or -N\nOriginal Order #: ${_tranId}`);
}
return isValid;
Main part is
Copy code
if (!isValid) {
    alert(`'The Order # is Invalid and only accepts -P or -N\nOriginal Order #: ${_tranId}`);
    Returns false after this
}
c
I mean code wise it seems like its ok. If false, display the alert and return false. Is something else setting a value? It should put you right back into the box that was invalid.
b
its common on chrome based browsers
its likely that he is returning false
👍🏼 1
and chrome is counting the focus changing to the alert
which netsuite counts as an attempt to change the field
which triggers the validateField again
c
Sounds reasonable considering chrome