Hello, does anyone know if there's anything specia...
# suitescript
l
Hello, does anyone know if there's anything special about date field that prevents it from being validated using
validateField()
? Every time I try to that, it goes into (in)finite loop. validateField() returns either result of a function call or true, function itself returns boolean only, but error appears regardless of the value. Now, it's not INfinite loop, as it takes anywhere between one and X iterations for validateField to finish - alert added below as a proof. Initially I was trying to use
dialog.alert()
, but thought the error may have something to do with it's async nature (mind you, script contains some debug code/logic). Error appears both in Chrome and Firefox (but not Edge?):
Copy code
function checkIfDateOrderIsCorrect(scriptContext) {
  const fieldId = scriptContext.fieldId;

  alert(fieldId);
  if (!['custrecord_field1', 'custrecord_field2'].includes(fieldId)) {
    return true;
  }

  return false;
}

function validateField(scriptContext) {
  if (!checkIfDateOrderIsCorrect(scriptContext)) {
    return false;
  }

  return true;
}
s
Well this logic tree seems pretty flawed... any time any field changes that isnt
custrecord_field1
or
custrecord_field2
your validateField is gonna return false.
l
True that, however return value of the function is set like that for debug purpose only. The thing is that validateField function is stuck in a loop. After I posted the above I took a look at channel search and looks like I'm not the first one to have that issue...
s
Copy code
//if fieldid not in my array
//return true;

//return checkerFn()
I would change to something like that
you ar elikely getting an endless loop from sourcing or things trying to set each other
l
No, it's not that... There's nothing else on that record. I have just put all logic directly into
validateField
function and returned true regardless, still have the same issue. It happens only on date field. In the past that was a Chrome issue only, but I experience it in both Chrome and Firefox.
b
try not to do anything that changes the focus on the field
id start with removing your alert
l
Well, will need some sort of ui response to the user. Initially I used
dialog.alert()
, that's how I found out about the date field issue. I can confirm that keeping focus on the date field doesn't initiate infinite loop any more though.
b
set the field back to a valid value (ignore the fieldChange), then show your alert
l
Actually the date is usually empty, but in case it fails any check, I'm throwing
dialog.alert()
and set date to empty value instead, with
ignoreFieldChange
flag. Seems to work both for dialog and native alert