I have a requirement, where we need to pick all the personIdExternal fields from the source data (may be different structure as well) and combine all then pass it to the query at the receiver channel.
From all the values, If any of the personIdExternal value is matching at SuccessFactor need to be fetch as response.
Groovy Script:
import com.sap.gateway.ip.core.customdev.util.Message;
import groovy.json.*;
import groovy.util.logging.*;
import com.sap.gateway.ip.core.customdev.util.Message;
import org.codehaus.*;
def Message processData(Message message)
{
def body = message.getBody(java.lang.String) as String;
def XmlDataObject = new XmlSlurper().parseText(body)
def xmldata = []
def s="";
XmlDataObject.'**'.findAll { it.name()== 'personIdExternal'}.each { a ->
xmldata << a.text() }
//Removed duplicates
//Removed duplicates
xmldata.unique()
def last = xmldata.last()
//Need to find the last value to remove "or" from it
//Need to find the last value to remove "or" from it
for (i in xmldata){
if (last == i){
s= s.concat("(personIdExternal eq ${i}) ");
}
else{
s= s.concat("(personIdExternal eq ${i}) or ");
}
}
message.setBody(s);
return message;
}
Output:
(personIdExternal eq 101) or (personIdExternal eq 112) or (personIdExternal eq 123) or (personIdExternal eq 144) or (personIdExternal eq 115) or (personIdExternal eq 167) or (personIdExternal eq 179) or (personIdExternal eq 189) or (personIdExternal eq 136) or (personIdExternal eq 182)
Happy Learning!!!
Happy Learning!!!
Nice code than you, got a question how you then doa post on ODATA V2 to successfactors of other paramters which are identified by the unique personIdExternal
ReplyDeleteRetrieve the field name like the same code as discussed in this blog and add the parameters with (and) operator, try this if this helps . Thanks
ReplyDeletenice post!!!
ReplyDeleteThanks for sharing great post !!
SAP SuccessFactors Online Training
SAP SuccessFactors Training in Hyderabad