cancel
Showing results for 
Search instead for 
Did you mean: 

UDF Question

Former Member
0 Kudos

Hi,

In my scenario i need to build a UDF for the next structure:

<b>http://www.directupload.net/show/d/748/Di5MbK3H.jpg</b>

<b>source</b>

<Record>

<KEY>"Firstname"</KEY>

<TEXT>Michael</TEXT>

<KEY>"Lastname"</KEY>

<TEXT>Jordan</TEXT>

<KEY>"Organisation"</KEY>

<TEXT>chicagobulls</TEXT>

</Record>

<b>Target</b>

<Customer>

<Firstname>Michael</Firstname>

<Lastname>Jordan</Lastname>

<Organisation>chicagobulls</Organisation>

</Customer>

<b>http://www.directupload.net/show/d/748/kc68N5xL.jpg</b>

Can anyone provide me any help regarding the constrution of UDF, as i'm not an expert in java code ...

Thanks in advance,

Fth

Accepted Solutions (1)

Accepted Solutions (1)

stefan_grube
Active Contributor
0 Kudos

Why do you want to use a UDF? You are doing well with your if construction.

Regards

Stefan

Former Member
0 Kudos

<b>Hello Stefan,Vijaya,Ananth</b>

I tried this first only for "Firstname"and they was Successfuly (if i disable fields "Lastname" and "Organisation").

But if i reply for "Lastname" and "Organisation" then give me an error.

<b>Cannot produce target element /ns0:MT_TARGET/Customer/Firstname. Check xml instance is valid for source xsd and target-field mapping fulfills requirements of target xsd</b>

(stefan)Hope this clears yours doubt

regards,

Fth

stefan_grube
Active Contributor
0 Kudos

Did you copy the constant?

Check, if the entry is still "Firstname".

If not, delete the constant and create a new one instead of copying it.

Regards

Stefan

Former Member
0 Kudos

Hello stefan,

it's worked if i send the all field values.

<b>http://www.directupload.net/show/d/748/o34Ok8jZ.jpg</b>

but not only <b>Firstname</b> and <b>Lastname</b> why?

http://www.directupload.net/show/d/748/szqOVLC5.jpg

Regards,

Fth

stefan_grube
Active Contributor
0 Kudos

Because all fields are mandantory (occurrance: 1..1).

You can add the function <i>mapWithDefault</i> between if and target,

or you change the occurrance of the targe element to 0..1

Regards

Stefan

Former Member
0 Kudos

Stefan, thank you !

Answers (3)

Answers (3)

prasad_ulagappan2
Contributor
0 Kudos

Hi Fatih,

As everyone said, it is not necessary to use UDFs here, instead you can use the Graphical mapping itslef. Also what you have done is good.

Since you have asked for it, here the code for UDF...

 String input = "Firstname";
if(a.equals(input))
return b;
else
return "";

Just create a UDF with two arguments, first one is for the key field and the next one is for text field.

This is a simple UDF. U can also perform this in many ways. U need to create 3 UDFs by changing the input value as "Lastname" and "Organisation".

Hope this helps..

Regards,

Prasad

Former Member
0 Kudos

Hi Fatih,

For your requirement you dont have to use UDF instead you can desing your mapping like this

<b>

Key  ------ Equlas ("Firstname") -------   | IF without Else |-----> Firstname (Target)
Text -------------------------------------------------|                       |

Key  ------ Equlas ("Lastname") -------   | IF without Else |-----> Lastname(Target)
Text -------------------------------------------------|                       |

Key  ------ Equlas ("Organisation") -------| IF without Else |-----> Organisation(Target)
Text -------------------------------------------------|                        |

</b>

Here I am assuming your Source structure definition is like this:

<b>

Record

Key --- 0-UB

Text--- 0-UB

</b>

Regards,

Ananth

Former Member
0 Kudos

HI,

As my understanding to your query you want to check if the <key> value is Firstname then put the <text> into <frstname>

You can try this

<KEY>--><equalsS>

<constant-fistname> --> <ifwithoutelse> <text> --> <Firstname>

So you are going to check first whether content of <key> is 'firstname' using 'equalsS' function in TEXT and hten if the reply is true then you mapt he value to <firstname>

Do the same for other receivers also.

Regards

Vijaya