cancel
Showing results for 
Search instead for 
Did you mean: 

Mapping field to particularly a[2] element in an array of values.

Former Member
0 Kudos

Hi Experts,

The source structure is

MT

RootNode

Parent(1..unbounded)

Contact(0..unbounded)

Phone(0..1)

Subscriber(0..)

I've to map a target node to Parent->Contact(1)->Phone->Subscriber node only and skipping all other occurences of Contact.

How do we do it in PI?

Regards,

Vishal

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

please explain your requirement clearly (how do you want to map)giving target structure also

RKothari
Contributor
0 Kudos

Hello,

If I understand your problem correctly, then you want to populate only 2nd number value out of suppose 10 values as an input.

You can write an UDF for it in which, just loop until the counter value is equal to 2. You can pass the output when counter = 2.

Also, you can try using copyValue function, which will pass only 2nd value.

BR,

Rahul

Former Member
0 Kudos

Hi Rahul,

I'll try copyValue function. Hope it works for my requirement.

Thanks,

Vishal

Former Member
0 Kudos

Hi Rahul,

I've requirement as below..

Consider Contact as Parent element and Telephone as child element. I need to map in the following manner..

Contact[2].Telephone ---> Number(Target node).

If it was Telephone[2]---> Number then copyValue function would be simple.

How can it be done for my requirement?

Regards,

Vishal

Former Member
0 Kudos

For Ex:

In my input file the following data come..

<?xml version="1.0" encoding="UTF-8"?>

<ns0:Messages xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge">

<ns0:Message1>

<DT>

<Contact >

<Telephone >9857468<Property>

<Description >EFGH<Description>

</Contact>

<Contact >

<Telephone >989897468<Property>

<Description >EFGH<Description>

</Contact>

</Contact>

</ns0:Message1>

</ns0:Messages>

I want only the 2nd Telephone value to be used in mapping.

RKothari
Contributor
0 Kudos

Hi,

You can use below mentioned udf.

Use Contact Node as input a and Telephone element as b

int i;

for(i=0;i<a.length;i++)

{

if(i == 1)

{

result.addValue(b<i>);

}

}

Only for the second value of Contact, the respective telephone value will be passed to target node.

BR,

Rahul

Former Member
0 Kudos

Hi,

We can't do result.addValue(b). So I used result.addValue(b[0]). Since it is b[0], it returns the first occurence of Telephone without taking into account the index of Contact. Please suggest me something more on this.

Regards,

Vishal

RKothari
Contributor
0 Kudos

Hi,

Please use b [ i ].

BR,

Rahul

Former Member
0 Kudos

Hi,

I didn't get you. Did you mean b.length? a.length is right. I want a[1].b[0] element to be returned.

Thanks,

Vishal

jyothi_anagani
Active Contributor
0 Kudos

>

> For Ex:

> In my input file the following data come..

> <?xml version="1.0" encoding="UTF-8"?>

> <ns0:Messages xmlns:ns0="http://sap.com/xi/XI/SplitAndMerge">

> <ns0:Message1>

> <DT>

> <Contact >

> <Telephone >9857468<Property>

> <Description >EFGH<Description>

> </Contact>

> <Contact >

> <Telephone >989897468<Property>

> <Description >EFGH<Description>

> </Contact>

> </Contact>

> </ns0:Message1>

> </ns0:Messages>

>

> I want only the 2nd Telephone value to be used in mapping.

Hi Vishal,

You want ony the 2nd Telephone numer....

Did you mean to say, If you are having 5 Telephone numbers you want to use only 2nd telephone number..

Mention your requirement properly...

Thanks.

Edited by: Jyothi Anagani on Aug 21, 2009 11:58 AM

RKothari
Contributor
0 Kudos

hello,

Sry some display issue.

As the occurance of telephone is 1.

Use either

 result.addValue( b<i>) or result. addValue(b[1])

BR,

Rahul

jyothi_anagani
Active Contributor
0 Kudos

Hi Vishal,

Map like this...

Telephone(Context Chnage)--


>UDF---->Output

UDF code...

int len = a.length;
if(len > 1)
{
  result.addValue(a[1]);
}
else
{
  result.addValue(a[0]);
}

This UDF will return the 2nd Telephone number if you are having more than 1 telephone....Otherwise it will return the same..

Thanks.

Former Member
0 Kudos

Hi All,

UDF Cache: Queue

Telephone(No context change)> UDF>Output

In UDF, i just wrote: result.addValue(a[2]). It worked.

Thanks,

Regards,

Vishal