cancel
Showing results for 
Search instead for 
Did you mean: 

Concatenating Mulitple fields into single string

abhay_aggarwal
Participant
0 Kudos

Hi Experts;

I am trying to Concate multiple fields at which are on source side and send into one string at target side.

Source

<Header>Occurance 1

F1

F2

F3(Hard Coded =A)

<Header/>

<item>Occurance 0 to N

F4

F5

F6(Hard Coded =B)

F7

F8

F9(Hard Coded =C)

F10

F11

F12

F13

<item/>

Target

<Data>

I am using the below code however it's not working

String finalString = "";

int count = streng.length;   //  input string array count

for(int i=0;i<count;i++)

{

     finalString = finalString + streng<i>;

}

result.addValue(finalString);

can anyone suggest on this.

Regards

Accepted Solutions (0)

Answers (5)

Answers (5)

Former Member
0 Kudos

Bhargavakrishna
Active Contributor
0 Kudos

Hi Abhay,

you can achieve this with the simple concat function available in Message mapping under text function.

i Dont know why you are going for UDF?

Refer below

In the above screen i used concat function to combine perner and amount to the target field amount.

You can find the result at the target side..

Regards

Bhargava krishna

ambrish_mishra
Active Contributor
0 Kudos

Hi Abhay,

please provide what you are the input parameters for the function and what you are trying to append.

Ambrish

abhay_aggarwal
Participant
0 Kudos

Hi Ambrish,

below is input which I want to put in single string:

{

"clientId";"Delver",

"state":"IL",

"zipcode":"60601",

"itemList":

[{partnum":"SPM11122233","sellerId":"100",":"","marketplacetype":"FBM", "mailable":"Y", "weight":"80",”qty”:”1”, “vendorcode”:””},

{partnum":"00834567901","sellerId":"",":"","marketplacetype":"DMM", "mailable":"Y","weight":"80",”qty”:”2”, “vendorcode”:””},

{partnum":"SPM22233344","sellerId":"200",":"","marketplacetype":"FBM", "mailable":"N","weight":"70",”qty”:”3”, “vendorcode”:””}

]

}

Item list Ocuurance is 0 to N . In Item list there almost 5 to 6 fields which are optional can and other 4 fields are mandatory.

I am using concate function for this but for Item list do I need to use UDF for this ..

Pls sugesst..

Regards

ambrish_mishra
Active Contributor
0 Kudos

Hi Abhay,

Now your requirement is more clear.

you would need to work with an advanced UDF (context) where you take all the required (header fields) and Item fields as input. After you have concatenated the header fields, run a for loop on one the item field (ideally mandatory) and concatenate the value with field names as per the sequence of parameters.

finally concatenate the header values to this output and then use the resultset object for output.

If you need help with coding, let us know but I suggest to give it a try. It would be a simple code.

Ambrish

former_member184720
Active Contributor
0 Kudos

Hi Abhay - Your requirement is not clear.

If you want to concatenate multiple fields under a segment, you can use the concat function right??

if you want append multiple occurrences of a field, i.e. as item is repeating multiple times and you want to concatenate all the occurrences of field F4  then you can use below UDF.[i did not tested it.. may be you have to modify a little]

Input parameter will be F4 field and select the Queue in the Execution type..

String s;

for (int i = 0;i<=F4.length;i++)

{

s = s+F4[i];

}

result.addValue(s);

Regards,

Hareesh

rajasekhar_reddy14
Active Contributor
0 Kudos

Why dont you use standard concat function to concat?