1 of 1 people found this helpful
You can use the function xs:dateTime($val) in the formula to validate the date value.
For example, you can pass the input value as "val=2018-09-05T02:02:33Z" and if the date-time value is wrong, it will show a validation error message
I had looked at that document, but I was not clear on how to check or enforce the datatype. I tried a few things but I can't get CAI to give me an error.
I don't have control of the input, so I have to assign it in a formula. To test I am passing 'Bad Date' to a DateTime field (using formula), but the value is accepted by the field and passed forward without failing.
Just in case I created a PO with a DateTime input (in_CheckData), which then is formatted to text in an assignment formula: infa:format($input.in_CheckData , 'YYYY-MM-DD'). This seems to simply pass the incorrectly formatted value without failing.
I also looked at the field properties, and I cannot find how to enforce a format within those properties either.
whats the required format and what's input value?
The required format is 'YYYY/MM/DD'. The problem is that the API (which I cannot change) will succeed regardless of the input. If I give it a date as 'DD/MM/YYYY' it will destroy data (overwrite with null) while giving a 200 status. This is the error I want to prevent, regardless of the input.
I expected the solution would be an is-date check, so I can confirm it is a date and then format or reject the input.
An option was for infa:format to error if the format cannot be met. Unfortunately when I tried it, it simply succeeds and returns the same input. I reviewed the usage example you provided, I think I am using it correctly, but it is not producing an error when I need it to.
Thank you Vinayak, this works well.
When I passed an incorrect value, it faulted and the error log indicated so:
Log: "Reason: Invalid dateTime value "BadDateAgain" (Non-numeric year component)"
I still wish there was something closer to is-date, but this will allow me to catch the errors. My main concern was the risk of false positives in the future.