cancel
Showing results for 
Search instead for 
Did you mean: 

How to check empty idoc fields in user defined function

Former Member
0 Kudos

Dear All,

I am working on an IDOC to file scenario. In my user defined function, I want to check whether a particular field of the idoc is populated. I can perform this test in message mapping by comparing the field with an empty constant.

How can I do the same test in an advanced user defined function? I have tried all the following, but none has worked so far

If (a.length == 0) ….

If (a[0].length == 0) …

If (a[0] == “”) …

If (a[0] == “ “)…

Am I doing something wrong?

Thx/Farshad

Accepted Solutions (1)

Accepted Solutions (1)

stefan_grube
Active Contributor
0 Kudos

To check whether an element is not available:

if (a.length == 0)

but you have to set cache to context. If you set cache to queue, it will not work, as in this case the context changes are part of the array a.

To check whether an element is empty:

if (a[0].equals(""))

Regards

Stefan

Message was edited by: Stefan Grube

Message was edited by: Stefan Grube

Former Member
0 Kudos

Thx everyone for your comments,

The equals() method was the answer. The == syntax was wrong.

Thx again/Farshad

Answers (2)

Answers (2)

moorthy
Active Contributor
0 Kudos

Hi Fatin,

Before calling user defined function, first check that field exists. For this you can make use of "Exists" node function in the message mapping.

So with this you can use If-Else logic. Then give this output into your UserDefined function.

Because if you don't have a value, then Idoc will not contain that field so there will not be any xml tag generated for that field.

Hope this helps,

Regards,

Moorthy

MichalKrawczyk
Active Contributor
0 Kudos

hi,

but you have the idoc field of not?

if so then try If (a[0] != null)

you can also try standard <b>Exist </b>function

from <b>Node functions </b>

if checks if the element exists or not

Regards,

michal