How I can do JSON file import and YAML import in ServiceNow
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi All,
I am working on catalog where I need to give user access to attach the attachment where the attachment can be JSON and YAML. How to parse these 2 file and upload the data in the target table
2 REPLIES 2
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
Hi @keshav77 ,
Can you please try to create a Business rule on Before on RITM table when insert and add below code
(function() {
var attachment = new GlideRecord('sys_attachment');
attachment.addQuery('table_sys_id', current.sys_id);
attachment.query();
while (attachment.next()) {
var sysAtt = new GlideSysAttachment();
var content = sysAtt.getContent(attachment);
var fileName = attachment.file_name.toString();
var data = null;
if (fileName.endsWith('.json')) {
data = JSON.parse(content);
}
if (fileName.endsWith('.yaml') || fileName.endsWith('.yml')) {
var yaml = new sn_impex.GlideYAMLParser();
data = yaml.parse(content);
}
if (data) {
var target = new GlideRecord('u_target_table');
target.initialize();
target.u_name = data.name;
target.insert();
}
}
})();
Please mark my answer correct and helpful if this works for you
Thanks and Regards,
Sarthak
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
3 weeks ago
@Ankur Bawiskar any suggestion this !!
