cancel
Showing results for 
Search instead for 
Did you mean: 

How to read sub field in groovy from main node List(Message Mapping Scenario)

former_member595526
Active Participant
0 Kudos

Could you pls help me out on reading sub field. for example I have

Sales node which has many sub fields (note: Sales node is coming as list)

Sales-->

->id

->name

->dept

can you help me reading this name field, Actually sales field is coming as list,I want to read all the names and concatenate it

sample xml code

<Sales>
 <id>101</id>
 <name>XDG</name>
 <dept>4XR1</dept>
</Sales>
<Sales>
 <id>102</id>
 <name>ZTY</name>
 <dept>6ZY1</dept>
</Sales>
<Sales>
 <id>103</id>
 <name>GER</name>
 <dept>27SD</dept>
</Sales>

Accepted Solutions (1)

Accepted Solutions (1)

manoj_khavatkopp
Active Contributor

It would be great if you provide a sample input xml and expected output xml so that forum can get better clarification.

But below is under my assumption:

Script :

import com.sap.it.api.mapping.*;
def void Append(String[] inp, Output output, MappingContext context) {
        String value1="";
        for(int i=0;i<inp.length;i++)
        {value1=value1 + inp[i];}
        output.addValue(value1);
}


Br,

Manoj

former_member595526
Active Participant
0 Kudos

Provided you sample xml, but my structure has only one Sales field and its sub field.

actually conversion is from IDOC to XML

manoj_khavatkopp
Active Contributor
0 Kudos

You're XML is similar like the one provided above , does the above script does not suffice your requirement ?

former_member595526
Active Participant
0 Kudos

Yes xml is similar but when it comes to Message mapping, It has only one sales node and its sub nodes. If i map directly on sales node, array length is coming as 3 but not able to read the data?

could you please help me how to map it with example you have provided?

manoj_khavatkopp
Active Contributor
0 Kudos

For the above provided XML, can you please provide expected output XML as well?

former_member595526
Active Participant
0 Kudos

yeah. all the names to be concatenated and mapped to single node

Something like this

<SalesNames>XDGZTYGER</SalesNames>

manoj_khavatkopp
Active Contributor
0 Kudos

It's similar to the one which i gave and i don't see any difference even i am concatenating note=N1 and N2 in my case and sending it to target , using that script. I am still not able to understand what is your ask.

rasjoshi
Active Contributor
0 Kudos

Hi Manoj,

Can this be achieved using CONCATENATE function in CPI?

I am new to CPI and trying to understand cases where grovy is needed.....

BR,

Rashmi

manoj_khavatkopp
Active Contributor
0 Kudos

Hi Rashmi ,

Concatenation takes a static number of fields :

Ex : FNAME: Manoj and LNAME: K so we can concatenate using the standard function as we know there are 2 fields.

But in this case it's a repeating node we need to concatenate the elements in the array.

It's the same way we do in PI.

Br,

Manoj

former_member595526
Active Participant
0 Kudos

Hi Manoj,

Could you please share your screenshot of Messagemapping in iflow

I have input coming as list but when it comes to iFlow Mapping

I see the following items only once

Sales

id

name

dept

If I map the name to SalesNames field directly with groovy script you provided above. I receive only one value always. the count is always only one. Hope you understand my problem. How to get all the names in this scenario.

In other ways, can you read the item List directly which has all information like title, information and quantity. In my case reading the entire sales list contains name.id,dept etc. is that possible in groovy to ready top node?

manoj_khavatkopp
Active Contributor

Name--->RemoveContext-->Script-->SalesName

former_member595526
Active Participant
0 Kudos

what does RemoveContext does?

Thanks for your support anyway. It worked. You saved me.

Answers (0)