XML Data Source - X-path assistance
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2016 09:39 AM
I am trying to import XML data, but cannot get the my desired result, and was hoping for some assistance. Part of the problem is that the XML nodes are mostly <col> each with different names. Ideally, I would like to make ServiceNow pull the <col>'s name attribute as the Table column name, and then pull the value of that node. Here is an example of what I am working with:
<?xml version="1.0" encoding="UTF-8" ?>
<knowledge_documents count="1747">
<row id="400430">
<col name="DOC_UUID" type="uuid">427B1963B812B4DA</col>
<col name="CREATION_DATE" type="date">1367352371</col>
<col name="RESOLUTION" type="string"><b>This<b> is my test data<ol><li>1</li><li>2</li></ol></col>
<categories>
<category>TOP>Internal Knowledge>Office>Software>Addin FS</category>
</categories>
</row>
<row id="498423">
<col name="DOC_UUID" type="uuid">428F3443B1784BA</col>
<col name="CREATION_DATE" type="date">1367352371</col>
<col name="RESOLUTION" type="string"><b>This<b> is my test data<ol><li>1</li><li>2</li></ol></col>
<categories>
<category>TOP>Internal Knowledge>Office>Software>Addin FS</category>
</categories>
</row>
</knowledge_documents>
No matter what X-Path I specify, Servicenow will not see the <col> nodes.
Here are some x-paths I've tried:
- /knowledge_documents/row (original x-path)
- /knowledge_documents/row/*
- //col[@name='TITLE']
Still can't get it to work. Is it possible to pull only specific data according to attribute data? I know X-Path can, but I couldn't get it working in ServiceNow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎01-28-2016 12:30 PM
Something like this should work for you:
var xmldoc = new XMLDocument(xmlString);
// Whatever attribute you want to get
nodelist = xmldoc.getNodes("//row/col[@name='DOC_UUID']");
for(i=0;i<nodelist.getLength();i++){
gs.print(nodelist.item(i).getTextContent());
}
You don't have to specify only columns in a row, but it can't hurt. So you could have the below for your xpath as well.
nodelist = xmldoc.getNodes("//col[@name='DOC_UUID']");
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2016 05:25 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎02-02-2016 07:48 AM
I misunderstood where you were doing this. I was just running a background script, but you're right that it's not working quite as expected when doing it as a data source. I'll see if I can figure it out.