Here is the sample doing some magic.
This is a Start->Conversion->Finish that illustrates the approach (it was in AMS package and is called LoadXml) AMS_LoadXML.zip (4.1 KB) .
The error handling is a bit lacking, though I made the effort in its respect, however since I am building the error XML manually, if reason or description contain special characters, the locding of manually-built XML will fail, and the resulting node will be empty.
- The workflow accepts the message according to UserSchemas/Standard/SingleDataValues.xsd schema, the conversion copies all the data from left to right.
- The worflow additionally declares a SingleValues message extension according to the same schema (conversion does not copy it from left to right, but insteadâŚ)
- The conversion picks dta/SingleValues/Strings/String1 and dta/SingleValues/Strings/String2 values, converting them to stirings
- The conversion has a script block contianing the fucntion called LoadXmlFileFrom written in JScript accepting three parameters - baseFolder, namePart1, namePart2
- The function builds the path to the file as <namePart1>_.xml, loads XML from that file and returns it back to the XSLT processing
- The XSLT part then copies the content of the returned XML to the output document
The incoming message for it looks like this (while testing I used it from DESPoster to trigger the workflow):
<msg:msg xmlns:msg="http://Epicor.com/InternalMessage/1.1">
<msg:req tag="AMS\LoadXml">
<msg:dta>
<SingleValues xmlns="http://epicor.com/schemas/SingleDataValues">
<Strings>
<String1>p1</String1>
<String2>p2</String2>
</Strings>
</SingleValues>
</msg:dta>
</msg:req>
</msg:msg>
The file I am loading is D:\Tst\p1_p2.xml D:\Tst\p1_p2.xml and looks like this:
<?xml version="1.0"?>
<SingleValues xmlns="http://epicor.com/schemas/SingleDataValues">
<Strings>
<String1>External</String1>
<String2>File</String2>
<String3>Content</String3>
</Strings>
</SingleValues>
The workflow has a message extension declared (this will help to consume the loaded content later on):
If you unzip the zip file to your âŚ\Epicor Service Connect\System\Services\DES\Processes\Custom\Packages\ folder (so that AMS folder appears right under Packages) and open the workflow in SC Workflow Designer, you should be able to review the only conversion).
Switch to the XSLT view.
At the beginning of the XSLT I am declaring two additional schema prefixes â xmlns:msxsl (needed to access MSXML xslt extensions and CustomHelper used to declare the helper function:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:msg="http://Epicor.com/InternalMessage/1.1"
xmlns:ext_SingleDataValues="http://epicor.com/schemas/SingleDataValues"
xmlns:CustomHelper="urn:my-scripts"
xmlns:scaf="urn:schemas-epicor-com:xslt">
A bit lower comes the script block that contains the LoadXmlFileFrom function written in JScript:
<msxsl:script language="JScript" implements-prefix="CustomHelper"><![CDATA[
function LoadXmlFileFrom(basePath, namePart1, namePart2) {
// Create a new XML Document object
var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.6.0");
xmlDoc.async = false;
xmlDoc.validateOnParse = false;
xmlDoc.resolveExternals = false;
xmlDoc.preserveWhiteSpace = true;
try
{
// Load data from external file
if (!xmlDoc.load(basePath + "\\" + namePart1 + "_" + namePart2 + ".xml"))
{
// Return the error in XML form
var parseErr = xmlDoc.parseError;
xmlDoc.loadXML("<ERROR Code=\"" + parseErr.errorCode.toString() + "\" Reason=\"" + parseErr.reason + "\" ></ERROR>");
}
}
catch(err)
{
xmlDoc.loadXML("<ERROR Number=\"" + err.number.toString() + "\" Description=\"" + err.description + "\" ></ERROR>");
}
return xmlDoc.documentElement;
}
]]></msxsl:script>
later on, within msg:usr seciton â manual creation of msg:SingleValues container element, content of which is filled with the output of the function invocation; when invoking the function, second and third parameter values are taken from the incoming message:
<xsl:element name="msg:usr">
<!-- Manually create the enclosing element -->
<xsl:element name="msg:SingleValues">
<!-- Parse all elements out of the returned XML and add them to the output document -->
<xsl:for-each
select="CustomHelper:LoadXmlFileFrom('D:\Tst', string(msg:dta/ext_SingleDataValues:SingleValues/ext_SingleDataValues:Strings/ext_SingleDataValues:String1), string(msg:dta/ext_SingleDataValues:SingleValues/ext_SingleDataValues:Strings/ext_SingleDataValues:String2))">
<xsl:copy-of select="."></xsl:copy-of>
</xsl:for-each>
<!-- Done! --></xsl:element>
</xsl:element>
And here is how the message looks in document tracking, when it reaches Finish element:
I hope this illustrates the approach in a reasonably clear way.
Regards,
Alex