How to check if an optional parameter is used

I have a Server Action that requires certain parameters but also accept optional parameters. I have however a hard time checking if an optional parameter has been explicitly set by the user or if it's just at it's default value (defaults can be valid inputs for my example). How can I detect this?

I have thought about setting a default value with values that are out of bounds but I have cases where that will never be an option (since the entire range of an integer for example is a valid input).

Hi Vincent,

You cannot. Not knowing the reason why you want to know if a value is passed I would suggest either the following:

  • Make your logic such that there is no reason to check if a value is provided, any value provided should be valid for the function to work, or alternatively:
  • Provide an extra Boolean input Parameter that describes if an optional parameter has its value passed, you can make this a optional parameter to with default unset (so false). Then only on those calls you provide a value in your optional parameter set the corresponding Boolean input parameter to true. This kind of constructs is also used sometimes in SOAP definitions for numeric and  oolean data.



Hi Vincent,

You can also decide not using default value. This way in the beginning of the action you check which ones are empty. This can be a problem if the user decide that he wants to pass the empty values. And after the check you can init the variables with the defaults you want. If the problem of this option is a no go for your case you should use the boolean input option of Daniel even if it gives more work for the consumer.



Hi Vincent,

Another approach (and perhaps less error-prone) is to make the attribute as mandatory and therefore you're forcing for the developer using it to think if he wants to pass the Default Value or not. In this way you are preventing that optional parameters fields are never filled, even when they should. On top of that, I would recommend to include a description on the parameter explaining its behavior (after all that's the purpose of descriptions) so whoever uses it has all the information in need.



My usecase is with an underlying javascript component (Leaflet) that I'm currently working on. There are plenty of functions in there that allow (for example) padding in the upperleft, lowerright or both (so 3 inputs). And to minimize the javascript created and thus send to the client I would like to have any method to verify if the values set in the property are send by the client or are just the system defaults (and then will be ignored). Normally I would check Undefined or Null but that is not available in Outsystems so I was hoping there was an alternative. 

Is there perhaps a method to check if a value is the default value? So I have a structure with a decimal with the default value of 1.0 (normally 0,0). Is there a method in outsystems check if the value is the same as the default value.

Hi Vincent,

Like Daniël already said, that's not possible. The only way is to set the default value of the Input Parameter to a value that's not a sane value, and detect that. So if e.g. you need positive integers, set the default to -1 so if you receive -1, you no no value has been set.

Hello Vincent

I had the some problem in the past and use a solution similar to the solution propose by Kilian... and it solve the question. ;)