BO parameter validation not working as expected

  • Christian
        2 years ago #30079

        Hi all,

        I want to pass a JSON data object to a business object. This data object has a self-defined data type. Even though the data is passed to the BO without any problems, the data validation throws an error and I do not understand why.

        I added three screenshots to my question: the definition of the data type, the definition of the business object, and the sent payload coming from my App in the browser. Everything works fine, but if I activate “Validate input” in the BO, I get an error when I call the BO via my app:

        “validationErrors”:[
        {
        “parameterName”: “***********”,
        “value”:{
        “Kunde”:”******”,
        “Fahrzeugklasse”:”********”,
        “Fahrzeug”:”******”,
        “Endtermin”:”28.01.22″,
        “Starttermin”:”07.01.22″
        },
        “errors”:”Bad JSON: 28.01.22; Literal for type Date malformed”
        }
        ]

        Noteworthy, I also do not get a validation error if I use the “Test” dialog in the BO and define the testing input data. Also important to note is that the both date values are coming from a UI5 date picker in my App.

        Do I have a mistake somewhere? And if not, how can I fix this without leaving out input validation?

        Thank you!

        Attachments:
        You must be logged in to view attached files.
        Armin Winkler
            Has successfully completed the online course Introduction
            Has successfully completed the online course Intermediate (200)
            Has successfully completed the online course Advanced (300)
            Has successfully completed the online course Basics (100)
          2 years ago #30086
          Up
          0
          Down
          ::

          Hi Christian,

           

          if you are using the data type “Date” for input parameters, Simplifier expects a date time string following the ISO 8601 standard (as defined here) with the time zone UTC. To achieve this in combination with the DatePicker widget that you are using in your application, you need to set the value of the property “valueFormat” “to YYYY-MM-ddTHH:mm:ss.sssZ”.

          However, as your time zone might not be UTC (see the code example below for +1 hours offset for German winter time), you still need to make sure that your date time string is set to 0 UTC offset. In order to do this, you can either instantiate a new Javascript Date object and pass the value from the DatePicker as input, then invoke the function toISOString on that object (like so: new Date(“2022-01-28T00:00:00.000+0100”).toISOString()) or let momentJS handle the formatting. Whatever you prefer, simply pass the result as parameter to your BO function and the validation won’t cause a problem anymore.

          If you don’t feel like doing all these formatting steps, another alternative would be to change the date fields in your struct data type to String, then you can pass the value from the DatePicker widget to the BO without having to change it at all.

           

          Hope this helps!

           

          Regards,

          Armin

          Christian
              2 years ago #30140
              Up
              0
              Down
              ::

              Hi Armin

              thank you very much for the explanation! I implemented a date “translator” in my server-side Business Object that acts as data layer. Here I can translate between ISO 8601 and the standard that is implemented by my RDS.

              Best regards

              Christian

            Viewing 3 posts - 1 through 3 (of 3 total)

            You must be logged in to reply to this topic.