The main problem is to get the correct field from the original payload and then map it alongside its analogous mapped counterpart. This is very difficult to do using graphical mapping alone, since we can’t loop over two different contexts and map simultaneously. The reason other solutions documented are able to solely use graphical mapping is that, as stated above, they rely on there being only a single record per payload, which doesn't require the same contextual considerations as the payload is basically flat.
So, a feasible strategy would be to save the required fields from the original payload in a hashmap with the record identifier as the key. Then we would use graphical mapping where we would map the old XSD of the receiver system (the one that doesn’t have the extended fields) with the new XSD with the extended fields included. Map all the shared fields together, map the identifier with the extended fields, and add a get script for the graphical mapping that uses as input the record identifier in order to output the saved hashmap fields into their correct attributes. The advantage of this approach is that it is straightforward and it doesn't require the creation of a new XSD with both payloads merged.
In this blog post we will showcase a post-exit implementation using Utilities Installation objects mapping into Agreement Terms objects in SAP Marketing Cloud. Inside each Installation we could have many nested Installation Facts. Each Installation Fact would belong to different attributes on the receiver payload. Not all Installations have facts. Here for this scenario, we use XmlSlurper to loop through the installations and get the record identifier to acquire the hashmap reference key and then loop through the facts of that record to collect the desired hashmap fields. We have made different hashmaps for each fact name, and we simply place the facts in the correct object when it’s found with the record key being the ISUContractID which is mapped as MKT_AgreementExternalID in the receiver payload.
import com.sap.gateway.ip.core.customdev.util.Message;
import java.util.HashMap;
def Message processData(Message message) {
//Body
def body = message.getBody(String.class);
def response = new XmlSlurper().parseText(body);
def installation = response.'**'.findAll { node -> node.name() == 'UtilitiesInstallation' }
def CDiscountMap = new LinkedHashMap();
def FDiscountMap = new LinkedHashMap();
def eMap = new LinkedHashMap();
for(i=0; i<installation.size() ; i++){
for(j=0; j<installation[i].UtilityInstallationFacts.size(); j++){
//ADD
if(installation[i].UtilityInstallationFacts[j].FactName == "CDiscount"){
CDiscountMap.putAll( [(installation[i].ISUContractID.text()): ['FactIndicator' : installation[i].UtilityInstallationFacts[j].FactIndicator,'StartDate' : installation[i].UtilityInstallationFacts[j].StartDate, 'EndDate' : installation[i].UtilityInstallationFacts[j].EndDate]]);
}
//ADD
if(installation[i].UtilityInstallationFacts[j].FactName == "FDiscount"){
FDiscountMap.putAll( [(installation[i].ISUContractID.text()): ['Percentage' : installation[i].UtilityInstallationFacts[j].Percentage,'StartDate' : installation[i].UtilityInstallationFacts[j].StartDate, 'EndDate' : installation[i].UtilityInstallationFacts[j].EndDate]]);
}
//ADD
if(installation[i].UtilityInstallationFacts[j].FactName == "eAbsAmtDisc"){
eMap.putAll( [(installation[i].ISUContractID.text()): ['Amount' : installation[i].UtilityInstallationFacts[j].Amount,'currencyCode' : installation[i].UtilityInstallationFacts[j].Amount.@currencyCode, 'StartDate' : installation[i].UtilityInstallationFacts[j].StartDate, 'EndDate' : installation[i].UtilityInstallationFacts[j].EndDate]]);
}
}
}
message.setProperty("cHashMap", CDiscountMap);
message.setProperty("fHashMap", FDiscountMap);
message.setProperty("eHashMap", eMap );
return message;
}
import groovy.xml.XmlUtil;
import com.sap.gateway.ip.core.customdev.util.Message;
def Message processData(Message message) {
def body = message.getBody(String.class);
def response = new XmlSlurper().parseText(body);
def titles = response.'**'.findAll { node -> node.uri.text().contains("Agreements(")}.each{ node -> node.replaceNode{}};
def nodeAsText = XmlUtil.serialize(response);
message.setBody(nodeAsText);
return message;
}
def void getFdiscount(String[] id, Output percentage, Output start, Output end, MappingContext context){
def newBody = new LinkedHashMap();
newBody = context.getProperty('fHashMap');
if(newBody.containsKey(id[0])){
percentage.addValue(newBody[id[0]].Percentage);
start.addValue(newBody[id[0]].StartDate);
end.addValue(newBody[id[0]].EndDate);
}
}
def void getediscount(String[] id, Output amount, Output currency, Output start, Output end, MappingContext context){
def newBody = new LinkedHashMap();
newBody = context.getProperty('eHashMap');
if(newBody.containsKey(id[0])){
amount.addValue(newBody[id[0]].Amount);
currency.addValue(newBody[id[0]].currencyCode);
start.addValue(newBody[id[0]].StartDate);
end.addValue(newBody[id[0]].EndDate);
}
}
def void getCdiscount(String[] id, Output status, Output start, Output end, MappingContext context){
def newBody = new LinkedHashMap();
newBody = context.getProperty('cHashMap');
if(newBody.containsKey(id[0])){
status.addValue(newBody[id[0]].FactIndicator);
start.addValue(newBody[id[0]].StartDate);
end.addValue(newBody[id[0]].EndDate);
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
16 | |
12 | |
8 | |
7 | |
7 | |
7 | |
6 | |
5 | |
5 | |
5 |