Introduction:
This article is a deep dive into a detailed comparison of payloads from SAP SuccessFactors OData and Custom MDF in this insightful article. We’ll break down the structure, key attributes, and data elements of both payloads, highlighting their unique strengths and how they can be effectively utilized. Join us as we explore practical examples and outputs that demonstrate the integration capabilities and optimize your HR processes!
Overview:
This article is a deep dive into a detailed comparison of payloads from SAP SuccessFactors OData and Custom MDF in this insightful article. We’ll break down the structure, key attributes, and data elements of both payloads, highlighting their unique strengths and how they can be effectively utilized. Join us as we explore practical examples and outputs that demonstrate the integration capabilities and optimize your HR processes!
Scenerio/Requirement:
We need to retrieve user IDs based on country groups from SAP SuccessFactors (SF) and cross-reference these with data in Custom MDF. The objective is to query the specified country groups in SF to obtain the relevant user IDs and then identify any users who have been removed from these country groups in SF as compared to the entries in MDF. This process is crucial for maintaining accurate and up-to-date user records, ensuring data integrity, and to find exact which user ids are removed from that group.
What we do in this blog/article:
In SAP CPI implementation scenarios, the comparative analysis of input payloads is essential for optimizing data and message flows. This blog explores a detailed examination of two XML payloads. Regardless of whether these payloads exhibit distinct structures or align closely, our primary objective is to identify and highlight data changes between the payloads and find removed users from the groups.
Solution:
This below solution is just an example and please change the solutioning accordingly to your requirement.
Lets initially query data for users from SF Odata where you filter the data based on group country = 'India'
For example when you query:
SF_Payload:
<?xml version="1.0" encoding="UTF-8"?>
<JobRequisition>
<JobRequisitionOperator>
<jobReqId/>
<usersSysId>User1</usersSysId>
<operatorRole>T</operatorRole>
</JobRequisitionOperator>
<JobRequisitionOperator>
<jobReqId/>
<usersSysId>User2</usersSysId>
<operatorRole>T</operatorRole>
</JobRequisitionOperator>
<JobRequisitionOperator>
<jobReqId/>
<usersSysId>User3</usersSysId>
<operatorRole>T</operatorRole>
</JobRequisitionOperator>
<JobRequisitionOperator>
<jobReqId/>
<usersSysId>User4</usersSysId>
<operatorRole>T</operatorRole>
</JobRequisitionOperator>
<JobRequisitionOperator>
<jobReqId/>
<usersSysId>User5</usersSysId>
<operatorRole>T</operatorRole>
</JobRequisitionOperator>
<JobRequisitionOperator>
<jobReqId/>
<usersSysId>User6</usersSysId>
<operatorRole>T</operatorRole>
</JobRequisitionOperator>
</JobRequisition>
Store the incoming payload from SF using property with "SF_payload" for future use.
In the next step, you are querying custom MDF object with the country = 'India' and you may have some sets of data.
Lets consider MDF Payload:
<?xml version="1.0" encoding="UTF-8"?>
<JobRequisition>
<JobRequisitionOperator>
<jobReqId/>
<usersSysId>User8</usersSysId>
<operatorRole>T</operatorRole>
</JobRequisitionOperator>
<JobRequisitionOperator>
<jobReqId/>
<usersSysId>User2</usersSysId>
<operatorRole>T</operatorRole>
</JobRequisitionOperator>
<JobRequisitionOperator>
<jobReqId/>
<usersSysId>User3</usersSysId>
<operatorRole>T</operatorRole>
</JobRequisitionOperator>
<JobRequisitionOperator>
<jobReqId/>
<usersSysId>User4</usersSysId>
<operatorRole>T</operatorRole>
</JobRequisitionOperator>
<JobRequisitionOperator>
<jobReqId/>
<usersSysId>User7</usersSysId>
<operatorRole>T</operatorRole>
</JobRequisitionOperator>
<JobRequisitionOperator>
<jobReqId/>
<usersSysId>User9</usersSysId>
<operatorRole>T</operatorRole>
</JobRequisitionOperator>
</JobRequisition>
And, store the incoming payload from SF using property with "MDF_payload" for future use.
Now we want to find the users that has been removed from SF_Payload where this data can be sent to functional team for their business purposes.
Groovy:
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashSet;
import java.io.ByteArrayInputStream;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.DocumentBuilder;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import org.w3c.dom.Node;
import org.w3c.dom.Element;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import java.io.StringWriter;
def Message processData(Message message) {
// Retrieve payloads from properties
def wfPayload = message.getProperty('SF_payload') ?: ''
def mdfPayload = message.getProperty('MDF_payload') ?: ''
// Check if payloads are present
if (!wfPayload || !mdfPayload) {
throw new IllegalArgumentException("One or both payloads are missing")
}
// Initialize DocumentBuilderFactory and DocumentBuilder
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance()
DocumentBuilder builder = factory.newDocumentBuilder()
// Parse the XML payloads
Document wfDoc = builder.parse(new ByteArrayInputStream(wfPayload.bytes))
Document mdfDoc = builder.parse(new ByteArrayInputStream(mdfPayload.bytes))
// Extract user IDs from WF payload
def wfUserIds = new HashSet<String>()
NodeList wfOperators = wfDoc.getElementsByTagName("JobRequisitionOperator")
for (int i = 0; i < wfOperators.getLength(); i++) {
Element operator = (Element) wfOperators.item(i)
NodeList userIdNodes = operator.getElementsByTagName("usersSysId")
if (userIdNodes.getLength() > 0) {
wfUserIds.add(userIdNodes.item(0).getTextContent())
}
}
// Extract user IDs from MDF payload and find those not in WF payload
def removedUsers = []
NodeList mdfOperators = mdfDoc.getElementsByTagName("JobRequisitionOperator")
for (int i = 0; i < mdfOperators.getLength(); i++) {
Element operator = (Element) mdfOperators.item(i)
NodeList userIdNodes = operator.getElementsByTagName("usersSysId")
if (userIdNodes.getLength() > 0) {
String userId = userIdNodes.item(0).getTextContent()
if (!wfUserIds.contains(userId)) {
removedUsers.add(userId)
}
}
}
// Create the result XML
Document resultDoc = builder.newDocument()
Element rootElement = resultDoc.createElement("RemovedUsers")
resultDoc.appendChild(rootElement)
for (String userId : removedUsers) {
Element userElement = resultDoc.createElement("RemovedUser")
userElement.appendChild(resultDoc.createTextNode(userId))
rootElement.appendChild(userElement)
}
// Convert result document to string
TransformerFactory transformerFactory = TransformerFactory.newInstance()
Transformer transformer = transformerFactory.newTransformer()
DOMSource source = new DOMSource(resultDoc)
StringWriter writer = new StringWriter()
StreamResult result = new StreamResult(writer)
transformer.transform(source, result)
// Set the result XML as the body
message.setBody(writer.toString())
// Optionally set additional headers or properties if needed
message.setHeader("ProcessingStatus", "Completed")
message.setProperty("RemovedUsersCount", removedUsers.size())
return message
}
For the above scenario, SF_payload and MDF_payload is compared and removed users from SF_payload has been identified.
For example the output for the above would be:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<RemovedUsers>
<RemovedUser>User1</RemovedUser>
<RemovedUser>User5</RemovedUser>
<RemovedUser>User6</RemovedUser>
</RemovedUsers>
And also the RemovedUsersCount property would have the value '3'. This output payload can be saved in a property for any uses such as sending it to the Admin via mail etc.
Applications:
Hope this blog gives some insights above the XML payloads comparison and figuring out the removed data.
Thanks,
Yogesh Kumar S
SAP Integration Suite SAP SuccessFactors Platform #sapcpi
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
14 | |
10 | |
8 | |
7 | |
6 | |
6 | |
5 | |
5 | |
5 | |
5 |