on 08-16-2007 3:19 PM
Hello people,
Ive a mapping issue. This is how the situation is
Input file looks like this with occurrence <b>0..4</b>
<b>OrganisationFormattedName</b>
Output file looks like this:
<b>CompanyName1
CompanyName2</b>
The value of the first OrganisationFormattedName has to be filled in CompanyName1 and the second value of OrganisationFormattedName in CompanyName2.
Can anyone help me to the right direction?
Regards,
Kamran
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Pushkar and others,
Pushkar, your solution was very helpfull and you will get definitly all my points. But when the source element doesn't have a OrganisationFormattedName tag I get the following error:
Cannot produce target element /mt_OrderBestand/PurchaseOrderHeader/ShipToAddress/CompanyName1. Check xml instance is valid for source xsd and target-field mapping fulfills requirements of target xsd
Any idea about that?
Regards,
Kamran
Message was edited by:
Kamran Vakili
Hi all,
Ive another question about the next situation, can I use the same function for the next situation?
Input file looks like this with occurrence 0..unbounded
<Item>
<ShipToLocation>
<Address>
<OrganisationFormattedName></OrganisationFormattedName>
</Address>
</ShipToLocation>
</Item>
Output file looks like this:
<LineItem>
<ShipToAddress>
<CompanyName1></CompanyName1>
<CompanyName2></CompanyName2>
</ShipToAddress>
</LineItem>
So for example there can be 2 Items in the source message therefore 2 OrganisationFormattedName.
In the target message we will have 2 LineItems and 2 CompanyName1 and 2 CompanyName2.
Regards,
Kamran
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
no, this is one where you would have to use a function like the one I provided above.
Or there is an easy way of using a Global count variable and each time you have your mapping with the copyvalue, in the copyvalue function use the global variable, and have a UDF increment that global variable right behind it.
If you need more elaboration, just ask.
Here's a step by step approach,
Create your global variable in mapping:
http://i161.photobucket.com/albums/t207/Reimius/CopyHelp1.jpg
http://i161.photobucket.com/albums/t207/Reimius/CopyHelp2.jpg
Create your UDF
http://i161.photobucket.com/albums/t207/Reimius/CopyHelp4.jpg
Create your mapping
http://i161.photobucket.com/albums/t207/Reimius/CopyHelp3.jpg
Hi Paul,
Thank you very much for your help. I followed your approach and I didn't get the required result.
My example looks like this:
Input file:
<Item>
<ShipToLocation>
<Address>
<b><OrganisationFormattedName>AAAA</OrganisationFormattedName>
<OrganisationFormattedName>BBBB</OrganisationFormattedName></b></Address>
</ShipToLocation>
</Item>
<Item>
<ShipToLocation>
<Address>
<b><OrganisationFormattedName>CCCC</OrganisationFormattedName>
<OrganisationFormattedName>DDDD</OrganisationFormattedName></b></Address>
</ShipToLocation>
</Item>
Output file should looks like this:
<LineItem>
<ShipToAddress>
<b><CompanyName1>AAAA</CompanyName1>
<CompanyName2>BBBB</CompanyName2></b>
</ShipToAddress>
</LineItem>
<LineItem>
<ShipToAddress>
<b><CompanyName1>CCCC</CompanyName1>
<CompanyName2>DDDD</CompanyName2></b>
</ShipToAddress>
</LineItem>
I didnt get this result.
Can you help me?
Regards
Kamran
Hi Pushkar,
I just tried that it didn't work.
I get this result:
<LineItem>
<ShipToAddress>
<CompanyName1>AAAA</CompanyName1>
<CompanyName2>BBBB</CompanyName2>
</ShipToAddress>
</LineItem>
<LineItem>
<ShipToAddress>
<CompanyName1>AAAA</CompanyName1>
<CompanyName2>BBBB</CompanyName2>
</ShipToAddress>
</LineItem>
Regards,
Kamran
Message was edited by:
Kamran Vakili
Kamran,
Check the mapping in the below URL, and let us know whether it suits your reqmt.
Mapping
http://www.flickr.com/photo_zoom.gne?id=1181884663&size=o
Result
http://www.flickr.com/photo_zoom.gne?id=1181884681&size=o
Best regards,
raj.
Kamran, combine my mapping with what Pushkar said, where he said to use copy value, use my method with the copyvalue + UDF. Then your second set of values should not be the same.
Since I assume you are using two copyvalue functions with their definitions 0 and 1, you will always just pull the first two elements of the element your mapping from, with the global variable I told you to define, each time you call an element with the copyvalue function it will set the variable one higher, so the next time you call the copyvalue function it will get the next element from the element your mapping from.
Hello,
Maybe I wasn't very clear so hereby a print screen of the mapping:
http://www.flickr.com/photo_zoom.gne?id=1182207125&size=o
In the mapping you see that Item in the source message is 0...unbounded.
And the mapping is:
Item to LineItem
Address toShipToAddress
OrganisationFormattedName to CompanyName1
OrganisationFormattedName to CompanyName2
Here you can see an example:
http://www.flickr.com/photo_zoom.gne?id=1182207137&context=photostream&size=o
There are 2 Items and 4 OrganisationFormattedName. And the result has to be:
CompanyName1 : AAAA
CompanyName2 : BBBB
CompanyName1 : CCCC
CompanyName2 : DDDD
And I dont get that...
Regards,
Kamran
Paul,
Thank you again for your reply.
I used your solution for my issue. And I didn't get the required result.
When I use this structure as my mapping:
OrganisationFormattedName <-CopyValue [0] -
OrganisationFormattedName <-CopyValue [1] -
The output will be like this if I have 2 Item tags:
CompanyName1: AAAA
CompanyName2: BBBB
CompanyName1: AAAA
CompanyName2: BBBB
And with this stucture the result is:
OrganisationFormattedName <-CopyValue [counter] -
OrganisationFormattedName <-CopyValue [counter] -
CompanyName1: AAAA
CompanyName2: AAAA
CompanyName1: AAAA
CompanyName2: AAAA
Did I do something wrong?
Regards,
Kamran
For some reason it looks like the counter isn't getting incremented.
did you initialize it correctly, it may be in the java section,
in global variables you put;
int counter =0;
instead of just
int counter;
you don't declare it as 0 there or it will always stay as 0;
make sure it's exactly like the second picture in my previous post.
http://i161.photobucket.com/albums/t207/Reimius/CopyHelp2.jpg
also check the UDFIncrement to make sure it has counter++; in it.
Kamran,
I hope this time the mapping logic will meet ur reqmt. If not kindly reply back.
I had assumed that for particular Item in source u will have only two company names. For Particular Line Item in taregt u will have only two company names.
Also source must have two companynames for each Item its mandatory!!
If my assumption is correct.Then follow the logic.
Mapping:
http://www.flickr.com/photo_zoom.gne?id=1196198164&size=o
http://www.flickr.com/photo_zoom.gne?id=1196198180&size=o
UDF :
http://www.flickr.com/photo_zoom.gne?id=1196198190&size=o
Results:
http://www.flickr.com/photo_zoom.gne?id=1196198210&size=o
http://www.flickr.com/photo_zoom.gne?id=1196198194&size=o
Best regards,
raj.
Paul,
<i>Beat me again raj... until next time!</i>
Paul you are seriously working on this issue. Really appreciate your time!!!
Surely Paul next time u will beat me...
Don't consider me as ur opponent rather consider me as friend, we are suggesting the the solution to our friends , am I right? There is no competition though!!
Cheers mate
@Kamran : In the solution I suggested please remove one input (Index) and run the same. Coz I'm not using that parameter inside UDF.
Best regards,
raj.
Kamran:
I worked same you working on..my scenario is SRM -XI-FTP... the mapping was done from PurchaseOrderRequest_out to xCML file... i used the following simple mapping with one UD "GetValue"
<b>Org.Name > Map with Default Value> Get Value--->Company Name</b>
Code for Simple UD " Get Value"
for(int i=0; i<a.length;i++){
if(i==0)
result.addValue(a<i>);
}
if you want first element give i == 0
second element give i == 1..
thats it
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
My documentation on the TakeWhich Function will solve whatever you need...
The TakeWhich function-
Use this function if you have an xml document with entries with the same xml tag in order, but you only want a certain entry for mapping. This will also work if you want a certain entry for many contexts of entries.
Function inputs are the node you want to map from, the number of the entry that you want, and the total number of entries in the context.
Example:
Function inputs- data, 3, 4
Source-
<row>
<data>test1</data>
<data>test2</data>
<data>test3</data>(we want this one)
<data>test4</data>
</row>
<row>
<data>test5</data>
<data>test6</data>
<data>test7</data>(and this one)
<data>test8</data>
</row>
Destination-
<destination>test3</destination>
<destination>test7</destination>
public void TakeWhich (String[] a,String[] b,String[] c,ResultList result,Container container){
/**
*This function is used to grab certain entries from series of entries with the same xml
*tag
*a- node with same xml tags, b- which node you want, c-number of nodes in a context
*Created by Paul Schroeder July 2007
*/
int i = Integer.parseInt(b[0]);
int i2 = Integer.parseInt(c[0]);
int count=1;
for(int j=0;j<a.length;j++)
{
if(count==i)
{
result.addValue(a[j]);
result.addContextChange();
}
if(count==i2)
{
count=0;
}
count++;
}
}
take out the result.addContextChange(); if you have your destination entries in the same context, which it looks like you do.
and in teh mapping use the XI provided function removeContexts before this function
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
For your case you need to create the 2 UDF for each Company name to filer the first value and second value. You can't do this with Standard functions according to my knowledge.
Create the UDF which always return the first element of OrganisationFormattedName and another UDF which always return the second element of OrganisationFormattedName map to CompanyName1 and CompanyName2 respectively.
Warm Regards,
Vijay
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Kamran,
I suggest you to use the two following mappings :
- UseOneAsMany
- Split by value
This would look like
OrganisationFormattedName -> UseOneAsMany ->Split by value ->CompanyName
You will have as many nodes created as there are occurences in your source field.
Regards,
Laurent.
Reward points if helpfull.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
82 | |
10 | |
10 | |
9 | |
6 | |
6 | |
5 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.