Creating Web API which can handle Nulls

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

Parents
  • 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 parameter
    then the Web API would return an error. In the third part, update the filter to return all of the
    data if the query parameter is null.
    1. In line 14, after the filter parameter but before the a!queryFilter() function, add the if()
    function
    2. Add the closing parenthesis for the if() function after the parenthesis on line 19. You can
    hard return after the parenthesis on line 19 and add the new parenthesis on line 20.
    3. Hard return after the if( on line 14
    4. 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 query
    parameter for name is null, return the full list from the database; else use the filter to
    return filtered results”
    a. condition: isnull(http!request.queryParameters.name)
    b. valueIfTrue: null
    c. valueIfFalse: a!queryFilter(...

  • 0
    Appian Employee
    in reply to frankt54

    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).

Reply Children