cancel
Showing results for 
Search instead for 
Did you mean: 

when combination of 2 fields is different,the node needs to be create in PI

Former Member
0 Kudos

Hi All,

I have a requirement,where only when the combination of 2 fields values are unique,node needs to be created in the target .

How to achieve this in Message mapping.

Ex

Field1 Field2 Target

1 2 Node formed

2 1 Node formed

2 2 Node formed

3 1 Node formed

3 1 node should not be formed

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

I created the required mapping. This is the test data I was using:


<?xml version="1.0" encoding="UTF-8"?>
<ns0:MT_test_src xmlns:ns0="urn:test2">
   <item>
      <Field1>1</Field1>
      <Field2>2</Field2>
   </item>
   <item>
      <Field1>2</Field1>
      <Field2>1</Field2>
   </item>
   <item>
      <Field1>2</Field1>
      <Field2>2</Field2>
   </item>
   <item>
      <Field1>2</Field1>
      <Field2>1</Field2>
   </item>
</ns0:MT_test_src>

This is the XML in and out:

[http://www.freeimagehosting.net/uploads/282404ad27.jpg]

This is the Graphic mapping used and the overview of the Message Type:

[http://www.freeimagehosting.net/uploads/c48c096b0b.jpg]

Hope this helps...

Edited by: Ofer Even-Tsur on Dec 7, 2010 3:00 PM Fixed second image URL

markangelo_dihiansan
Active Contributor
0 Kudos

Hello,

The mapping suggested by Ofer is correct, however, it can still be simplified by adding collapseContext right after the splitByValue for the item mapping. e.g


Field1 --> concat --> sort:ascending -->splitByValue:valueChanged --> collapseContext --> item
Field2 --> /

Hope this helps,

Mark

Edited by: Mark Dihiansan on Dec 8, 2010 3:29 AM

Former Member
0 Kudos

Mark is correct.

Answers (5)

Answers (5)

Former Member
0 Kudos

Hi All,

Thanks for your responses.

My issue resolved

Former Member
0 Kudos

Hi All,

Thank you for the responses.

But in my case the values coming are not constant values so i cannot use FIXVALUE.

Is there any other method to acheive this in Message Mapping.

I tried concatenation of values>sort>splitvalue(value change)>collapse context-> target node(segment).Its working

But its not working for field level.

Can any one help me on this

Former Member
0 Kudos

Hi Ramesh,

Field 1= Field 2----> If > then Send a constant(any value) then Map to creatif--> Target Node

Thanks,

sunilchandra007
Active Contributor
0 Kudos

>

> Hi All,

> I have a requirement,where only when the combination of 2 fields values are unique,node needs to be created in the target .

> How to achieve this in Message mapping.

>

> Ex

>

> Field1 Field2 Target

> 1 2 Node formed

> 2 1 Node formed

> 2 2 Node formed

> 3 1 Node formed

> 3 1 node should not be formed

No need to go for UDF. This can be easily done by combination of standard functions concat , FixValues and createIf.

Concate your 2 fields and maintain it in key of FixValues and keep the value as true for which node should be create So node would only be created when it satisfy the comination.

Maintain your FixValues with default as false.

Key      Value 
12       true
21       true
22       true
.................

Field1---
             | concat ---- FixValues --- createIf --- Target
Field2---

Regards,

Sunil Chandra

Former Member
0 Kudos

Hi Ramesh,

You need to write a UDF to check the field 1 and field2 are equal. If equal, then use the Createif node function to create the node.

Thanks,

former_member472138
Active Contributor
0 Kudos

Hey,

public class CompareTwoStrings {

public static void main(String[] args) {

// this will print; the compiler is smart

String s1 = "smile";

String s2 = "smile";

// this will print

if (s1 == s2)

System.out.println("s1 and s2 are ==");

}

}

and return the value and use createif funtion.

Regards

Pothana

Edited by: Pothana Yadav on Dec 7, 2010 11:08 AM

sbuttler77
Active Participant
0 Kudos

The easiest way is probably a UDF in which you loop over field1 and field2 and add true/false

to the resultqueue. as per your requirement. You can use the createif function to create the target

based on the UDF's resultqueue.