cancel
Showing results for 
Search instead for 
Did you mean: 

UDF help required.

Former Member
0 Kudos

Hi,

<data>

..<Person>

....<Contact>

............<Telephone>

...................<Number>984574123658</Number>

.............</Telephone>

......</Contact>

....<Contact>

............<Telephone>

...................<Number>984574123658</Number>

.............</Telephone>

......</Contact>

..</Person>

</data>

Target filed 'PHONE' needs to be mapped only to Contact[0].Telephone.SubscriberNumber, and not Contact[1].Telephone.SubscriberNumber.

How can this be done in UDF?

Thanks,

Vishal

Accepted Solutions (1)

Accepted Solutions (1)

former_member200962
Active Contributor
0 Kudos

Not changing the Context of the Source Telephone number field should do the trick. Normally we raise the Context (or remove etc) so that the entire message is scanned for the required nodes......if we let the context remain as is then only the first instance is considered......so this logic may work for your case as well.....give it a try.

I hope that by mentioning Contact0 you mean to say the very first instance of the Contact node.

Regards,

Abhishek.

Former Member
0 Kudos

<data> First Occurence

..<Person>

....<Contact>

............<Telephone>

...................<Number>1</Number>

.............</Telephone>

......</Contact>

....<Contact>

............<Telephone>

...................<Number>2</Number>

.............</Telephone>

......</Contact>

..</Person>

</data>

<data>2nd occurence

..<Person>

....<Contact>

............<Telephone>

...................<Number>3</Number>

.............</Telephone>

......</Contact>

....<Contact>

............<Telephone>

...................<Number>4</Number>

.............</Telephone>

......</Contact>

..</Person>

</data>

When 2 records are coming, I need to create 2 IDocs. The field PHONE(0..1) in the second IDoc should get the first 'Number' of 2nd data. Instead it's taking second 'Number' of 1st data.

Regards,

Vishal

Former Member
0 Kudos

HI,

Please Use below function in seq.

1. set the context of < Number> to <data>.

2 then Use collapse context function.

3. then Split by value and map to the target field.

Shweta.

Former Member
0 Kudos

Thanks a lot. It works fine if Contact[0] has telephone. There's this possibility:

<data>* First Occurence*

..<Person>

....<Contact>

............<Telephone>

...................<Number>1</Number>

.............</Telephone>

......</Contact>

....<Contact>

............<Telephone>

...................<Number>2</Number>

.............</Telephone>

......</Contact>

..</Person>

</data>

<data>2nd occurence

..<Person>

....<Contact>

......</Contact>

....<Contact>

............<Telephone>

...................<Number>4</Number>

.............</Telephone>

......</Contact>

..</Person>

</data>

In the above case, PHONE(2nd IDOC) has value 4, which is in Contact[1] of 2nd <data>. Telephone's occurence is 0..unbounded.

Former Member
0 Kudos

Telephone's occurence is 0..unbounded.

Sorry, Only Contact's occurence is 0..unbounded. Telephone's is 0..1

Former Member
0 Kudos

So, first I need to check if it's Contact[0],then check if Telephone exists for Contact[0]. If 'true' I've to send the corresponding 'Number'. Is there any way to link these 3 fields?

Edited by: Vishal.P.Kulkarni on Sep 11, 2009 12:02 PM

Former Member
0 Kudos

Hey,

The solution I gave earlier should work even if the telephone tag is not occuring in evry contact.

The first step of the solution takes care of that.

1. set the context of < Number> to <data>. :: It puts all the <Telephone> in <data> tage in one context. Hence even if your second contact in data has telephone then it will appear at first level if first contact doesnot have telephone. Please check this.

2 then Use collapse context function.

3. then Split by value and map to the target field.

Shweta.

Former Member
0 Kudos

It puts all the <Telephone> in <data> tage in one context. Hence even if your second contact in data has telephone then it will appear at first level if first contact doesnot have telephone.

You are right. But, when Telephone doesn't exist in Contact[0] of 2nd <data>, the target node PHONE in 2nd IDOC shouldn't be created.

Since,second contact in data has telephone and it appear's at first level if first contact doesnot have telephone, it means PHONE is getting mapped to Conatc[1].Telephone.Number.

Always, PHONE should be mapped to Conatc[0].Telephone.Number.

If Telephone is not there in Conatct[0], PHONE shouldn't be created.

Thanks,

Vishal

former_member187339
Active Contributor
0 Kudos

Hi Vishal,

Try this:

Number (Context - Contact) -> Collapse Context ->Splitbyvalue(Each value) -> OUTPUT

Regards

Suraj

Former Member
0 Kudos

Sorry, it doesn't work..

Former Member
0 Kudos

Hey try this:

1. set the context of < Number> to <data>.

2. Use mapwithdefault node function: I expect it will replace supress with the default. Hence when we dont have contact[0] telephone then it will get replace with the default value.

2 then Use collapse context function.

3. then Split by value

4. Create if Node function: Give the condition that create if value is not equal to <value you gave in map vwith default >

5. map to the target field.

Hope this works

Former Member
0 Kudos

in the 4th step instead of creatif you can use ifwithoutelse also. here pass the value only if it is not same as default value.

shweta

Former Member
0 Kudos

mapwithdefault node function will replace suppress with the default only when Context is at Telephone or Contact. But it doesn't when Context is data.

Thanks,

Vishal

Former Member
0 Kudos

Yes you are right.

So lets try this.

1. set the context of < Number> to <contact>.

2. Use mapwithdefault node function:

3. remove context

4. Then use FormatByExaple to get the context back(first prameter will be o/p of 3rd step, 2nd parameter will be <contact> node with context set at <data> ).

5 then Use collapse context function.

6. then Split by value

7. Ifwithoutelse function: Give the condition that if value is not equal to <value you gave in map vwith default >

8. map to the target field.

Shweta.

Former Member
0 Kudos

Function formatByExample: Queues have not equal number of values

I am getting the above runtime exception at formatByExample.

Former Member
0 Kudos

As per my understanding of your source structure. every contact has Only one Telephone number. Telephone is with O..1 occurance. When we mapped it with map with default (give here some default value), it should insert telephone number in the contact where ever it was missing. Hence we should have ame number of value. Please see where are we missing. Investigate by seeing the queues.

Shweta.

Former Member
0 Kudos

hey check you have set the context to <data> for the <contact> before passing it to FormatwithExample.

Shweta

Former Member
0 Kudos

Thank you very much Shwetha. Your understanding about structure is correct. And now I am getting the desired result.

Where I missed was:(This could be of help if someone refers this for same problem)

Basically, my mapping was in 2 stages:

Source -> Data

Data->IDOC

In this question I explained you only regarding the 2nd mapping.

In the first mapping I had disabled Number field. Hence, there was a mismatch in the number of values of 'Number' and 'Contact'.

I enabled the 'Number' field and the number of values of 'Number' and 'Contact' are same now and hence the desired result.

Thanks,

Vishal

Edited by: Vishal.P.Kulkarni on Sep 11, 2009 2:29 PM

Answers (5)

Answers (5)

former_member187339
Active Contributor
0 Kudos

Hi Vishal,

Can you provide your output structure and mapping involved,... I am sure the mapping of the parent of target field(where telephone need to be mapped) has to do something with the result.

Regards

Suraj

Former Member
0 Kudos

as sweta mentioned above


Number---->collapseContext----->SplitByValue(each Value)----->PHONE

right click on number choose context to change the context to Data

Former Member
0 Kudos

Hi,

You can also try this:

Remove context of Sub.Contact Number Source structure and then use Index (Statistics Func) with fixed 0 value.

Regards,

Shweta.

Former Member
0 Kudos

Hi

You do not require any UDF for this, remove context changes for source field, map it to target field with copyValue() function with position 0. Try it will work.

thanks

VS

Former Member
0 Kudos

Hi,

Infact you can keep occurance of target field Phone just 0--1 then also it will take value of just first

....<Contact>

............<Telephone>

...................<Number>984574123658</Number>

.............</Telephone>

......</Contact>

try this, if it works.

Thanks,

Hetal