Import XML file info
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2025 01:18 AM
Hi,
We are receiving large xml file as a attachment through API and we are using saveBodyAsAttachment method because it has lot of info. So once the file is received we want to import the data. I tried data source and defined the Xpath but the problem is we have values that needs to import from different nodes. Attached sample image of XML. We like to import Policy_ID and Total values
So looking for options to import the file either can we define multiple xpath or get values directly from file
Any suggestions. Thank you.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2025 07:04 AM
Hi @chandukollapart - Try setting Xpath for each row to /COMPLIANCE_POLICY_REPORT on the data source, then you should be able to extract POLICY_ID from <FILTERS> node and TOTAL from <CONTROL_INSTANCES> node in your transform map.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2025 10:32 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2025 10:37 AM - edited 01-27-2025 08:31 PM
What's the error? I created a sample file of the same structure (sample.xml) and then created a table transform map with the following script:
(function transformRow(source, target, map, log, isUpdate) {
try {
// Extract XML from the source table fields
var headerXml = source.u_header; // Replace with the actual field name for the header XML
var controlInstancesXml = source.u_control_instances; // Replace with the actual field name for the control instances XML
// Parse the XML for <POLICY_ID> from <FILTERS>
if (headerXml) {
var headerDoc = new XMLDocument2();
headerDoc.parseXML(headerXml);
var policyIdNode = headerDoc.getNode('/HEADER/FILTERS/POLICY_ID');
if (policyIdNode) {
var policyId = policyIdNode.getTextContent();
target.u_policy_id = policyId;
} else {
// POLICY_ID node not found in HEADER XML
}
} else {
// HEADER XML is empty or missing
}
// Parse the XML for <TOTAL> from <CONTROL_INSTANCES>
if (controlInstancesXml) {
var controlDoc = new XMLDocument2();
controlDoc.parseXML(controlInstancesXml);
var totalNode = controlDoc.getNode('/CONTROL_INSTANCES/TOTAL');
if (totalNode) {
var total = totalNode.getTextContent();
target.u_policy_total = total;
} else {
// TOTAL node not found in CONTROL_INSTANCES XML
}
} else {
// CONTROL_INSTANCES XML is empty or missing
}
} catch (e) {
log.error('Error during Transform Map script execution: ' + e.message);
}
})(source, target, map, log, action === "update");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-26-2025 11:03 AM
Thank you for the response. Below is the error and I saw this KB related to that error. "om.glide.db.impex.datasource.DataSourceException: Incorrect or missing XPath expression"
https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0832837
So to run that transform script file has to load completely right?