cancel
Showing results for 
Search instead for 
Did you mean: 

Error Executing UDF

former_member192105
Participant
0 Kudos

Hello,

I have a source message like

<Source>

<Field>CSV</Field>

</Source>

Value of Field can be either CSV or XML. I have to check if the Field has value CSV or XML and also if the Field exists.

I am able to do it using standard functions in mapping, but I want to check it using a UDF.

For the first part (check CSV or XML) I wrote a UDF:

if((!var1.equals("CSV")) || (!var1.equals("XML")))

{

return "fail";

}

else

{

return "pass";

}

Even if Field = CSV or XML, the UDF returns fail (it should return pass). What is wrong in the UDF?

Also how should be the UDF if I have to check for existence of Field?

Field --> UDF --> TargetField

If source Field does not satisfy the conditions then TargetField should not be generated.

~Thanks.

Accepted Solutions (1)

Accepted Solutions (1)

RKothari
Contributor
0 Kudos

Hello,

Please try the below if condition:

if( !(var1.equals("CSV")) || !(var1.equals("XML")))

Also how should be the UDF if I have to check for existence of Field?

You can use Exists node function.

If source Field does not satisfy the conditions then TargetField should not be generated

Use IF without else function. If you are using UDF, use

result.addValue(ResultList.SUPPRESS);

-Rahul

former_member192105
Participant
0 Kudos
You can use Exists node function.

I am able to check using Exists function, wanted to check how it will be in a UDF.

result.addValue(ResultList.SUPPRESS);

Will this work if I have UDF with Single Values option?

~Thanks.

RKothari
Contributor
0 Kudos

Hello,

You can check the field existence either by checking its length or compare it with null (like "").

Result method won't work with single value function.

-Rahul

former_member192105
Participant
0 Kudos

Hello,

You can check the field existence either by checking its length or compare it with null (like "")

I tried changing to All values of Context and then used var1.length == 0, but even this seems to be wrong.

"" surely does not stand for null. I have a JAVA mapping where I have checked for the existence of nodes using

if(Field == null)

Actually none of the source fields will be repeating, so I am wondering why to use Queue/ Context option!

~Thanks.

Former Member
0 Kudos

Hi,

Chk this:

String bb="";

if(var!=null)

{

if( (var.equals("CSV")) || (var.equals("XML")) )

{

bb= var;

}

}

return bb;

Note: Plz chk syntax errors if any.

Thanks

Amit

former_member192105
Participant
0 Kudos

Hello,

No, it is not working

Source message:

<Source>

<SField>CSV/ XML</SField>

</Source>

Target message:

<Target>

<Details>

<TField>constant_value</TField>

</Details>

</Target>

My requirement is to check in UDF if SField exists and (Sfield = CSV or SField = XML). only when this is satisfied create the target node Details otherwise do not create.

Requirement is to check in UDF if SField does not exists or if SField does not contain CSV or XML, only when this is satisfied (SField absent or does not have CSV/ XML) create the target node Details otherwise do not create.

Sorry for the mess-up

~Thanks.

Edited by: Abhishek01 on Jan 12, 2011 1:11 PM

Former Member
0 Kudos

Hi,

Please use following peace of code as UDF:

If(var1.equals("CSV") || var1.equals("XML"))

{

return "false";

}

else

{

return "true";

}

Use following mapping:

SField --> exists --> if -->(true) --> (SField --> UDF) -->createIf -->Details

-->(false) >createif> Details

Regards,

Nayan

RKothari
Contributor
0 Kudos

Hello,

>>if SField does not contain CSV or XML

Please use the below if condition.

if( !(var1.equals("CSV")) && !(var1.equals("XML")))

Also, if you want to calculate the length of a string you can use function length() for example:string.length() .

Also, I belive there is no need of writting UDF, you req can be handled using GUI function.

Use Exists, NOT, AND and IF without Else functions.

-Rahul

former_member192105
Participant
0 Kudos

Hello Nayan and Rahul,

I have managed to check if not CSV or XML using (i feel this is not a good UDF code, but is working):

if ((var1.equals("CSV")) || (var1.equals("XML")))

{

return "pass";

}

else if ((!var1.equals("CSV")) || (!var1.equals("XML")))

{

return "fail";

}

else

{

return "pass";

}

But I am still not able to check if the node exists or not, when the field does not exist the UDF fails (it should create the target node Details).

I will check for it tomorrow. meanwhile if there are suggestions, they are most welcomed.

~Thanks.

stefan_grube
Active Contributor
0 Kudos

>

result.addValue(ResultList.SUPPRESS);

> Will this work if I have UDF with Single Values option?

Your requirement will not work with 'single value' option.

You have to change it for 'context' option.

Then you can do this:

if (var1.length == 0) // node is empty
   result.addValue(ResultList.SUPPRESS);
else if (var1[0].equals .... )
  result.addValue("");
else
  result.addValue(ResultList.SUPPRESS);

Edited by: Stefan Grube on Jan 12, 2011 1:46 PM

former_member192105
Participant
0 Kudos

Hello,

Below UDF is working as per my requirement:

if (var1.length == 0) // node is empty
   result.addValue("");
else if ((var1[0].equals("CSV")) || (var1[0].equals("XML")))
  result.addValue(ResultList.SUPPRESS);
else
  result.addValue("");

~Thanks

Answers (0)