How to read XML file ?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2022 01:22 AM
When a user uploads a file to a record, I'm unable to read the contents of an xml file without getting everything inside. Right now I'm able to use 【GlideSysAttachment】 and 【GlideTextReader】 to use the content stream. This enables me to get a string line by line of the xml document. However, it does not include the xml tags and anything inside the xml.
Example:
XML
<userdata>
<user>
<firstname>Belly3</firstname>
<lastname>Tripath</lastname>
</user>
<user>
<firstname>Belly1</firstname>
<lastname>Tripath</lastname>
</user>
<user>
<firstname>Belly2</firstname>
<lastname>Tripath</lastname>
</user>
</userdata>
Script
var attachment = new GlideSysAttachment();
var agr = attachment.getAttachments('u_rpa_account',current.sys_id);
if (agr.next()) {
var attachmentContent = attachment.getContent(agr);
gs.addInfoMessage(attachmentContent+'====='+JSUtil.type_of(attachmentContent));
}
Using the above code, I getting "undefined and null". It is appearing in the line with "gs.addInfoMessage(attachmentContent+'====='+JSUtil.type_of(attachmentContent))".
Is there something wrong with how I'm setting this up?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2022 01:29 AM
Hi,
so you want to read the XML file?
when you print the content does it show as XML string?
If yes then you can use XML parser for that XMLDocument class
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2022 01:33 AM
Hi,
are you in scoped application or global for your above script?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2022 01:42 AM
Hi Ankur,
Good day. thanks for your quick response.
When I print the attachmentContent, I got nothing but "undefined"....
BTW, I'm in scoped application.
Any Advise Pls?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2022 01:56 AM
then you should add application cross scope privilege so that attachment can be read
Ideally it should automatically create these 2 entries; but if not then you create on your own
For me I am getting the XML file printed in background script in scoped app
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader