I have an XMLPort (import). One of the elements is a Record, and there's several Elements underneath that line up with the fields (ie: Order Header::"Bill to Name")
Each element also has sub elements that contain information about how the XML Port should behave, which are supplied dynamically by the sender of the XML. Example:
I'm trying to figure out how to dynamically access those sub-elements. My first thought was in marketplace_order::OnBeforeInsertRecord, I might be able to access them. However, the only way I've been able to do this so far is to assign the value to a string DataSource (such as Additional_info1 in the screenshot).
This isn't really feasible, since there are hundreds of nodes, and I need to do them dynamically.
Ideally, there'd be something like
"for each element directly under marketplace_info ...... find node with name "error" ..... if that element has a value, stop XML port and throw up a message with value"
...
The only other thing I can think of is for every single elemtn (document_type, no in the example)-- in OnAfterAssignField or OnAfterAssignVariable , call a function-- "DoCommonThing()"-- it would require pasting DoCommonThing into every OnAfterAssignField / OnAfterAssignVariable
It also occurs to me that an XMLPort, which structurally sound, might not be the right tool for what I'm looking to do?
Comments
I would try to pre-load the file in OnPreXMLport into a DotNET XML Variable (or XMLDOMDocument object if it is supposed to work in Classic Client, then use a XPath search expression to find a list of nodes including some specific text (error?), or element names, if found then throw an error, or iterate through returned node list and do whatever else needs to be done.
Slawek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
One way is like you suggested - to include a bit of the code on every node in OnAfterAssignField or OnAfterAssignVariable, call some function on it checking for errors.
Another way would be to build a custom buffer table where additional field/error handling data could be stored, base the XMLport on that table, and the in OnInsert open make a copy of the record into a Record Ref variable (using REcref.GETTABLE(buffer) ) and then loop through its fields looking for error codes in there.
If you build the buffer in some specific way, like keeping additional information fields next to each other you could do simple FOR based loop iterating through fields of your interest, and after successful check do a TRANSFERFIELDS to your real destination.
XPath based search is nice as you don't have to worry that much about the structure - you can build your XPath search expression to find nodes of your interest in any part of the XML structure.
Slawek
Dynamics NAV, MS SQL Server, Wherescape RED;
PRINCE2 Practitioner - License GR657010572SG
GDPR Certified Data Protection Officer - PECB License DPCDPO1025070-2018-03
No PM,please use the forum. || May the <SOLVED>-attribute be in your title!