cancel
Showing results for 
Search instead for 
Did you mean: 

Adding two XML files based on condition using Groovy in CPI

shivaprasad1
Participant
1,353

Is there any way to merge two XML using groovy in CPI based on condition .

Though I can do this using content enricher but it is not a best practice when it comes to bulk load (several thousands of records).

Consider I have two XML files from two request replies

XML1:

</PerPerson>

<PerPerson>

<personIdExternal>1234</personIdExternal>

<dateOfBirth>1953-07-06T00:00:00.000</dateOfBirth>

</PerPerson>

<PerPerson>

<personIdExternal>5678</personIdExternal>

<dateOfBirth>1962-05-27T00:00:00.000</dateOfBirth>

</PerPerson>

</PerPerson>

XML2:

<PerPersonal>

<PerPersonal>

<firstName>QWE</firstName>

<lastName>ASD</lastName>

<personIdExternal>1234</personIdExternal>

</PerPersonal>

<PerPersonal>

<firstName>LKJH</firstName>

<lastName>LPOI</lastName>

<personIdExternal>5678</personIdExternal>

</PerPersonal>

</PerPersonal>

OUTPUT XML: Based on personIdExternal merging should happen

</PerPerson>

<PerPerson>

<personIdExternal>1234</personIdExternal>

<dateOfBirth>1953-07-06T00:00:00.000</dateOfBirth>

</PerPerson>

<PerPersonal>

<firstName>QWE</firstName>

<lastName>ASD</lastName>

<personIdExternal>1234</personIdExternal>

</PerPersonal>

<PerPerson>

<personIdExternal>5678</personIdExternal>

<dateOfBirth>1962-05-27T00:00:00.000</dateOfBirth>

</PerPerson>

<PerPersonal>

<firstName>LKJH</firstName>

<lastName>LPOI</lastName>

<personIdExternal>5678</personIdExternal>

</PerPersonal>

</PerPerson>

Any script idea on this ?

Thanks
Shiva

Accepted Solutions (1)

Accepted Solutions (1)

Sriprasadsbhat
Active Contributor

Hello Shiva,

If you are using navigations ( in a single query you can get PerPerson and PerPresonal ) then dont think there will be huge differerence on performance compared to writing a script to perform correlation.

Regards,

Sriprasad Shivaram Bhat

Answers (2)

Answers (2)

ankitkumarpatel
Explorer
0 Kudos

Hey Shiva, there is one more way to solve this, you can use HashMap to store only related content and use content XML writer to get the desired output, this will be simple and fast as well.

Sriprasadsbhat
Active Contributor
0 Kudos

Hello Shiva,

Please try concept of navigation which avoids usage of multiple calls to SFSF.Refer below blog and make use of levels while modeling your SFSF odata query.

https://blogs.sap.com/2020/08/11/successfactors-integrations-beginners-guide-api-user-creation-and-c...

Regards,

Sriprasad Shivaram Bhat

shivaprasad1
Participant
0 Kudos

Hi Sriprasad,

Thank you for your response

We can do that way too, but if number of entities are increasing, performance decreases and I was suggested to do that through groovy.

Is there any way that we can do with groovy?

Thanks

Shiva