Hi everyone,
I'm trying to do a simple web API which can handle nulls values, but I'm having problems using the if statement to set it up. Can someone please help me. Thank you
filter: a!queryFilter(
field: "name",
operator: "=",
value: if(isnull(http!request.queryParameters.name)," " ,http!request.queryParameters.name), )
Discussion posts and replies are publicly visible
There is actually a separate "is null" operator, so you probably would want to separate this out by using conditional logic around your entire Query Filter. Something like this would work:
filter: if( a!isNullOrEmpty(http!request.queryParameters.name), a!queryFilter( field: "name", operator: "is null" ), a!queryFilter( field: "name", operator: "=", value: http!request.queryParameters.name ) )
One other important note: the vale you have there for " " is technically not null - a space and null are not considered equivalent in Appian.
Perfect, but I forgot to mentioned that i need to use a if statement. this is the instructions I have to follow.
The filter works with the test request, but if an external system did not send a query parameterthen the Web API would return an error. In the third part, update the filter to return all of thedata if the query parameter is null.1. In line 14, after the filter parameter but before the a!queryFilter() function, add the if()function2. Add the closing parenthesis for the if() function after the parenthesis on line 19. You canhard return after the parenthesis on line 19 and add the new parenthesis on line 20.3. Hard return after the if( on line 144. Use the following parameters (if you use the parameter names for this function,remember to use them for all parameters) in the if() function to say, “if the queryparameter for name is null, return the full list from the database; else use the filter toreturn filtered results”a. condition: isnull(http!request.queryParameters.name)b. valueIfTrue: nullc. valueIfFalse: a!queryFilter(...
Oh in that case you just don't need what I put in lies 3-6 - just replace that whole part with null. Once you do that, the filter will return null if the name parameter is null, and a filter of null just means don't apply a filter (i.e. return everything).
Thank you, it work.