How to validate for null in wM 4.6

Hi,

My service needs to validate the input data for null before processing.
How can i set it up in wM 4.6.

Thanks,
Sana

Sana,

There may be different ways to do this.

In the flow, you can compare the input values with $null and throw exception.

In case, if you want to apply this to various services, then

  1. Write one simple service which will check no of inputs supplied are not NULL
  2. Go to Input/Output section of your service (for which you want to validate) Select ‘Validate Input’ Option and
  3. Use the ‘input’ text box to point to the service written in first step.

You can try with this. And if you come across any other solution then please let me know.

Regards,
Paras

Sana,

You didn’t mention the type of service you are creating. You can use a Branch statement in Flow to check for null. Just set the “label” property to “$null” from the drop down list and then use “$default” to handle all non-null cases.

However, most times when you want to check for null values, you really want to check for null or empty string. The best way to do this in Flow is to use a regular expression in the “label” property.

As Rob has written several times here, a useful regex that will match any non-null or non-empty value is “/[^ ]/” (without the quotes). I used to keep a printout of his regular expression eZine article on my desk until I finally memorized a few of the more useful patterns.

Mark

Hi,

Thanks for the solution.I created a common service checkFieldNull which checks for null.I call checkFieldNull service in the main service.I map the “fieldToCheck” to the checkFieldNull service “inputField”.I want to generate an error message stating the “fieldToCheck” is null.
How can i go about this.

Thanks,
Sana

Sana,

Do you want to continue even though the field is NULL?
If answer is NO then you can throw an exception and use try/catch block to catch that exception.

Do you need me to explain how you can do it? If YES then paste your code here, I will add steps to it.

You can mail me at paras.halingale at yahoo.co.in or at otis.com

Regards
Paras

Paras/Mark

I have created a service to check for null and empty string.
But the check is not successful for null.
I am pasting the code below.

Branch (evaluate labels=true)
sequence(label:%checkField% == null || %checkField% == “”)
logErrorMsg(custom service already exists)
exit $flow

The above code works only with empty string,but not with null

Mark,

I tried with regex,but it is not able to check for null or empty strings.

Branch (evaluate labels=true)
sequence(label:/[^]/)
doNothing
sequence(label:$default)
logErrorMsg(custom service already exists)
exit $flow

Can anyone let me know what changes are needed for the above piece to succesfully check for null.

Thanks,
Sana

evaluate labels = false

Hi Sana,
Try the following:

Branch (evaluate labels=true)
sequence(label:%checkField% == $null || %checkField% == “”)
call logErrorMsg
exit $flow
sequence(label: $default)
continue

Regards,
Bhawesh
exit $flow

Your service is unecessary. You can use a Branch on the field to check with evaluate labels = false. The label of the null or empty branch should be a regular expression of “/[^ ]/” (without the quotes. The label of the second branch can either be a value you are expecting or “$default” (no quotes).

Don’t overengineer this.

Mark

Hi Mark,

As explained in the Regular exp eZine article,i have a
branch on the field with evaluate label=false

label of /[^ ]/ for non-null,not empty,no spaces
and
label of $default

It works fine except for null.It takes the /[^ ]/ path.
Have i missed something.

Thanks,
Sana

Hi Sana,
I guess you are confused with the string literal “null” with $null. Your code is correct, but while testing your code you type the string null and then it takes the /[^ ]/ path, which it is supposed to.

A input with value “null” is not the same as NULL input. A NULL input means either the input is not present in pipeline or if it is present, it has no value.

Pls. let me know if I guessed the problem correctly or not?

Regards,
Bhawesh.