Salesforce
This topic is related to Boomi
integration, the scenario I am now covering is to concatenate the specific XML
tags. For instance I have a below IDOC document tags
<?xml version="1.0"
encoding="UTF-8"?>
<E1EDKT1>
<TDID>Z007</TDID>
<TSSPRAS>E</TSSPRAS>
<TSSPRAS_ISO>EN</TSSPRAS_ISO>
<E1EDKT2>
<TDLINE>SalesOrderNotesLine1</TDLINE>
<TDFORMAT>*</TDFORMAT>
</E1EDKT2>
<E1EDKT2>
<TDLINE>SalesOrderNotesLine2</TDLINE>
<TDFORMAT>*</TDFORMAT>
</E1EDKT2>
<E1EDKT2>
<TDLINE>SalesOrderNotesLine3</TDLINE>
<TDFORMAT>*</TDFORMAT>
</E1EDKT2>
<E1EDKT2>
<TDLINE>SalesOrderNotesLine4</TDLINE>
<TDFORMAT>*</TDFORMAT>
</E1EDKT2>
<E1EDKT2>
<TDLINE>SalesOrderNotesLine5</TDLINE>
<TDFORMAT>*</TDFORMAT>
</E1EDKT2>
<E1EDKT2>
<TDLINE>SalesOrderNotesLine6</TDLINE>
<TDFORMAT>*</TDFORMAT>
</E1EDKT2>
<E1EDKT2>
<TDLINE>SalesOrderNotesLine7</TDLINE>
<TDFORMAT>*</TDFORMAT>
</E1EDKT2>
<E1EDKT2>
<TDLINE>SalesOrderNotesLine8</TDLINE>
<TDFORMAT>*</TDFORMAT>
</E1EDKT2>
<E1EDKT2>
<TDLINE>SalesOrderNotesLine9</TDLINE>
<TDFORMAT>*</TDFORMAT>
</E1EDKT2>
<E1EDKT2>
<TDLINE>SalesOrderNotesLine10</TDLINE>
<TDFORMAT>*</TDFORMAT>
</E1EDKT2>
<E1EDKT2>
<TDLINE>SalesOrderNotesLine11</TDLINE>
<TDFORMAT>*</TDFORMAT>
</E1EDKT2>
<E1EDKT2>
<TDLINE>SalesOrderNotesLine12</TDLINE>
<TDFORMAT>*</TDFORMAT>
</E1EDKT2>
<E1EDKT2>
<TDLINE>SalesOrderNotesLine13</TDLINE>
<TDFORMAT>*</TDFORMAT>
</E1EDKT2>
</E1EDKT1>
|
In above IDOC entries, I need to fetch first 10 TDLINE tag
and make it to one single string and after first 10, it would discard all the
TDLINE. So for this, we need to write the Groovy scripting in Dell Boomi integration
process. Please see below process image.
In above figure first it gets the SAP Order IDOC and just
before map I used Data Process node, I have written the groovy scripting
language which would concatenate the first 10 lines of above order IDOC and and
set the result in Property and after that in map it would use that Property to
map with Salesforce object. See the below groovy code.
import java.util.Properties;
import java.io.InputStream;
import org.jdom.input.SAXBuilder;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.xpath.XPath;
import org.jdom.output.XMLOutputter;
import com.boomi.execution.ExecutionUtil;
for( int i = 0; i < dataContext.getDataCount(); i++ ) {
InputStream is =
dataContext.getStream(i);
Properties props =
dataContext.getProperties(i);
// Build XML
Document
SAXBuilder builder
= new SAXBuilder();
Document doc =
builder.build(is);
XPath PricingNotes;
PricingNotes =
XPath.newInstance("//IDOC/E1EDKT1[TDID='Z007']/E1EDKT2/TDLINE");
XPath SalesNotes;
SalesNotes =
XPath.newInstance("//IDOC/E1EDKT1[TDID='Z002']/E1EDKT2/TDLINE");
MSGFN =
PricingNotes.selectNodes(doc);
PARWN = SalesNotes.selectNodes(doc);
Integer NotesCount
= 0;
Integer NotesCount2
= 0;
String TdLine =
"";
String TdLine2 =
"";
result = new
StringBuffer();
result2 = new
StringBuffer();
for(int
ak=0;ak<MSGFN.size();ak++){
if(NotesCount < 10){
result.append(MSGFN[ak].getText()+System.getProperty('line.separator'));
NotesCount = NotesCount +1;
}
}
for(int
ab=0;ab<PARWN.size();ab++){
if(NotesCount2 < 10){
result2.append(PARWN[ab].getText()+System.getProperty('line.separator'));
NotesCount2 = NotesCount2 +1;
}
}
TdLine = result.toString();
TdLine2 =
result2.toString();
// Create an XPath statement to search for
the element or elements you care about:
ExecutionUtil.setDynamicProcessProperty("SalesOrderNotes",
TdLine , true);
ExecutionUtil.setDynamicProcessProperty("PricingNotes",
TdLine2 , true);
XMLOutputter
outputter = new XMLOutputter();
is = new
ByteArrayInputStream(outputter.outputString(doc).getBytes("UTF-8"));
dataContext.storeStream(is, props);
}
|
If you see the above yellow highlighted code, it is fetching
only those nodes which are under E1EDKT1
main tag and surely this tag exists multiple time in IDOC, so to capture only
those E1EDKT1 node which has a qualifier of [TDID='Z007'] and after that it
would to the child node E1EDKT2 and in that child node the TDLINE tag exists.
So we used XPATH to fetch the XML node and similar logic used in second yellow highlighted
line but this time Qualifier is change. After that the green highlighted code
shows that it select the specific XPATH criteria node. After that, gray highlighted
code set the TDLINE text into the groovy PROPERTY which are “SalesOrderNotes”
and “PricingNotes”.
Now it’s about to turn for MAP node. In Map, you would use
the Get Dynamic Process property and get the property that we have set in
groovy code.
You can than map this property to any of the Salesforce object
field.