Data action with empty/null input contract field

Hello,

I would like create a data action with an input contract which accepts null value.
My use case is the following : if the value is filled it gives a result if not , a result is given with a defaut value

In my example, I have made test with the input contract tAcw.
When I configued with no value, I get this error :

8. Execute: The request could not be understood by the server due to malformed syntax.

  • REST call for action execute failed. Message:Request to backend service failed. Response from web service: {"message":"Must populate at least one of the parameters [gt, gte, lt, lte]","code":"bad.request","status":400,"messageParams":{},"contextId":"1240ab46-0190-4225-ad1a-3ce2716a6237","details":[],"errors":[]} [ad5abbb0-c1fc-48fe-920c-6c345b916328]

I have configured the request body template with this code for the tAcw which should accept "null" value
{
"type": "metric",
"metric": "tAcw",
"range": {
"lte": "#if( {input.tAcw} ){input.tAcw}#else ${input.tAcw}=10#end" }
}

I have attached the export action for more details

Many thanks for your hints
jeremy

POST-TEST-NULL-value-20200720154152.custom.json (4.0 KB)

Hello,

There might be other ways to do this.
But I tried the following (Request Configuration - text below is when using Simple definition) and it seems to work.

"lte": "#set( mydefault = "10" )#if( {input.tAcw} )${input.tAcw}#else$mydefault#end"

Regards,

Hi Jerome,

thanks for your help
I have replaced by your suggestion int the Request Body Template, but now I get this error :

2. Validate draft definition: The request could not be understood by the server due to malformed syntax.

  • Action POST TEST NULL value failed validation. Errors: [Template validation failed for 'config.request.requestTemplate'. Details: Encountered "mydefault" at validate config.request.requestTemplate[line 55, column 20] Was expecting one of: ... "{" ... ]

It seems there is a problem with the variable mydefault, do you have made modification from my data Action sent?

thanks
jeremy

Sorry, the $ sign got removed when I did the cut&paste from my data action to the forum (forgot to escape the $ to keep it displayed).

"lte": "#set( $mydefault = "10" )#if( ${input.tAcw} )${input.tAcw}#else$mydefault#end"

Many thanks it works!
Jerome, you talked me about other ways for achieve this request, you can told me a little more?
thanks again!

I meant that there might be other ways that I don't know. :slight_smile:
First time I tried a velocity if/else to replace a null value.

I did try (unsuccessful) to put the value directly after the else (without going through the mydefault variable).
I could make it work when the value was string with a to z characters.
But it didn't work with the integer value.
So instead of trying to figure out if this could be done that way, I preferred to use the variable and #set (which worked).

From my side, tested many things without success :wink:
thanks :+1:

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.