Simple validation through link on API Before Save Script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • cardigansam
    Junior Member
    • Oct 2022
    • 6

    Simple validation through link on API Before Save Script

    I'm looking to forbid a record from being created if a One-side of the one-to-many is too old. I can write code that works in the sandbox, but converting it over to the pre-save script is giving me a run for my money. Right now, I have:

    if (entity\isNew() && workorder.rodate < datetime\addDays(datetime\now(), -30)) {
    recordService\throwBadRequest("Work Order is Too Old!");
    }

    But this simply generates a 500 error when attempting to save a new record on the many-side. Without being able to sandbox it, I'm not sure where it fails.

    The workorder field is housing the related record detail (And you can't via the UI create the recrod without the link being prepopulated, so it'll always be there). the rodate field is simply the date field of the related record.
Working...