on 01-12-2011 10:11 AM
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
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
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
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.
>
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
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.