how can we import excel file into import set table using script and excel cells not columns titles
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2024 01:48 AM
Hi,
I need to import an Excel file into an existing import set table using a script (a business rule is triggered when attaching the Excel file). However, this file can be in different languages each time, so I suppose I have to use the cell numbers, not the column titles. Does anyone have an idea how to do that?
Thank you for your help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-10-2024 01:58 AM
Hi @Nessrine,
please try below script:
// Example script to process an attached Excel file
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_name', 'your_table_name');
gr.addQuery('table_sys_id', current.sys_id); // Assuming current is the current record context
gr.query();
if (gr.next()) {
var attachmentSysId = gr.getUniqueValue();
var importSetAPI = new GlideImportSet();
var importSet = importSetAPI.getImportSetBySysID('your_import_set_sys_id'); // Replace with your import set sys_id
// Set the source XML to the attachment content
var attachment = new GlideSysAttachment();
var fileContent = attachment.getContent(attachmentSysId);
importSet.setXMLData(fileContent);
// Process the import set
var importSetRow = new GlideImportRow(importSet, importSet.getRowID());
var rowSysId = importSetRow.insert();
if (rowSysId) {
gs.info('Excel file imported successfully.');
} else {
gs.error('Failed to import Excel file.');
}
}
Thank you, please make helpful if you accept the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-27-2025 01:26 AM
I have been looking for GlideImportSet() in the ServiceNow documentation for a while and I have not find it. Are you sure this is correct?