cancel
Showing results for 
Search instead for 
Did you mean: 

How to Extract particular field from a string using UDF java function

Former Member
0 Kudos

I have one source field: EMPDETAILS.

this field is getting the below data

-


<ProcessEmployeeChangeResponse xmlns="http://www.bl.edu/">

<EMPDETAILS>&lt;?xml version="1.0" encoding="utf-8" standalone="no"?&gt;

&lt;Employee PersonnelNumber="98432" FirstName="Robert" MiddleName="Dix" LastName="Bob" Department="00000014" Group="" EffectiveDate="12/17/2001 9:30:47 AM" Action="Z1" SapUserID="10rbob" EmailAddress="rbob@bl.edu" DefaultPassword="*" Status="Success" /&gt;</EMPDETAILS>

</ProcessEmployeeChangeResponse>

</soap:Body>

</soap:Envelope>

-


i want to write a User defined function (UDF) using JAVA to extract the EmailAddress to assign th target field "CommunicationID" (this is the target field)

Can any can help me to write Java userdefined function for this purpose.

Thanks

Dhanus

Accepted Solutions (1)

Accepted Solutions (1)

former_member214364
Active Contributor
0 Kudos

Hi Dhanush,

i am giving UDF code to extract email id:rbob@bl.edu /

i assumed that always you will get email id in this string format <b>EmailAddress="[ID]"SPACE</b>.

value within <b>[]</b> can change.

This is <b>Value</b> UDF.

int st_index = a.indexOf("EmailAddress=");

int ind_space = a.indexOf(" ",st_index);

String str = a.substring(st_index("EmailAddress=".length())1,ind_space-1);

return str;

Here <b>a</b> is input field from source message.

Please let me know if you have any issues with this UDF.

Cheers,

Jag

Former Member
0 Kudos

Hi Jag,

thank you very much for your help. the provided java code is working for both EmailAddress and MiddleName ( there is no pace in between EmailAdress). when i try to use same code for extracing "Employee PersonnelNumber" as this has space between Employee and PersonnelNumber, so it is giving me java error, can you please modify given java code accordingly, Please do me this favoure i am grateful to u as i am not good in writing java functions.

thanks

Dhanush.

former_member214364
Active Contributor
0 Kudos

Hi Dhanush,

i am giving reusable UDF code that means you can use this code to extract any field value from your source messages.

i am sure this code serves all needs.

//write your code here

int st_index = a.indexOf(b);

int ind_space = a.indexOf("\"",st_index + b.length()+1);

String str = a.substring(st_index(b.length())1,ind_space);

return str;

<b>Note:-</b> a,b are input fields

Here <b>a</b> is source field from source message type

<b>b</b> is constant value i.e if you want to extract <b>EmailAddress</b> from source message constant value should be <b>EmailAddress=</b> or

To extract <b>Employee PersonnelNumber</b> just give constant value as <b>Employee PersonnelNumber=</b>

Please let me know if you want further details about this UDF.

Cheers,

Jag

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi

can you please provide your source structure and the target structure.

for this, in the graphical mapping map the source field (that contains the email id )

with the target field communication ID.

if still face the problem please reply me back

Thanks

Rinku

Former Member
0 Kudos

Hi Dhanush,

Pls find the below link,

assign points if helpful

Regards,

Naresh.K

Former Member
0 Kudos

hey dhanush,

Can you provide both the source and target structure ??