Friday 5 October 2018

Picklist/ Lookup comparison in SAP CPI/HCI

Lookup and compare the two payload from the input and try to filter out the <label> field and return it.


Test data:

<?xml version="1.0" encoding="UTF-8"?>
<multimap:Messages
xmlns:multimap="http://sap.com/xi/XI/SplitAndMerge">
<multimap:Message1>
<Picklist>
<Picklist>
<optionId>301</optionId>
<locale>en_GB</locale>
<label>Permanent</label>
</Picklist>
<Picklist>
<optionId>346</optionId>
<locale>en_GB</locale>
<label>Associate</label>
</Picklist>
<Picklist>
<optionId>304</optionId>
<locale>en_GB</locale>
<label>Active</label>
</Picklist>
<Picklist>
<optionId>352</optionId>
<locale>en_GB</locale>
<label>Permanent</label>
</Picklist>
</Picklist>
<Employee>
<EmpEmployment>
<EmpEmployment>
<startDate>2018-04-01T00:00:00.000</startDate>
<personIdExternal>50000006</personIdExternal>
<userId>50000006</userId>
<endDate></endDate>
</EmpEmployment>
<EmpEmployment>
<startDate>2018-05-09T00:00:00.000</startDate>
<personIdExternal>50000006</personIdExternal>
<userId>3</userId>
<endDate></endDate>
</EmpEmployment>
</EmpEmployment>
<EmpJob>
<EmpJob>
<userId>50000006</userId>
<employeeClass>352</employeeClass>
</EmpJob>
<EmpJob>
<userId>3</userId>
<employeeClass>346</employeeClass>
</EmpJob>
</EmpJob>
</Employee>
</multimap:Message1>
</multimap:Messages>


Output:

Permanent
Associate

GroovyScript:

def Message processData(Message message) {
    def body = message.getBody(java.lang.String) as String
    def root = new XmlSlurper().parseText(body)
    def xmldata1 = []


    def xmldata2 = []
    def xmldata3 = []
    def i=0;
    def j=0;
       root.'**'.findAll { it.name() == 'optionId'}.each { a ->
    xmldata1 << a.text()}
    root.'**'.findAll { it.name() == 'label'}.each { a ->
    xmldata2 << a.text()}
    root.'**'.findAll { it.name() == 'employeeClass'}.each { a ->
    xmldata3 << a.text()}
  
    for(j = 0; j < xmldata3.size(); j++)
    {
    for(i = 0; i < xmldata1.size(); i++){
   
        if( xmldata1[i] == xmldata3[j])
        {
       return xmldata2[i]   
        }
}
   }
}







No comments:

Post a Comment