Get property information of attached Excel file
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2024 09:08 PM
I would like to read an Excel file attached to a ServiceNow record and retrieve the property information of the Excel file.
The property information of an Excel file is "ProgramName" and "Creator" listed in "Excel->property->Origin" etc.
ServiceNow has an existing GlideExcelParser that can read Excel files, but
GlideExcelParser is aware that it is not possible to read the property information of an Excel file.
If anyone knows the method, please let me know.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-18-2024 11:50 PM
Unfortunately, you are correct that the GlideExcelParser in ServiceNow is not designed to read the property information of an Excel file. It is primarily used to read the data within the Excel file, not the metadata or properties of the file itself.
However, you can use a workaround to achieve this. Here are the steps:
1. Use a third-party library that can read Excel file properties. Apache POI is a popular Java library that can do this. You can use it in a Script Include to create a custom method for reading Excel file properties.
2. Upload the Apache POI library to ServiceNow. You can do this by creating a new Script Include record and pasting the library code into the Script field.
3. Create a new Script Include that uses the Apache POI library to read Excel file properties. Here is a sample code:
javascript
var ExcelPropertiesReader = Class.create();
ExcelPropertiesReader.prototype = {
initialize: function() {
},
readProperties: function(attachmentSysId) {
var attachment = new GlideRecord('sys_attachment');
if (attachment.get(attachmentSysId)) {
var inputStream = new GlideSysAttachment().getContentStream(attachmentSysId);
var workbook = new org.apache.poi.ss.usermodel.WorkbookFactory.create(inputStream);
var properties = workbook.getProperties();
var programName = properties.getProgramName();
var creator = properties.getCreator();
return {
programName: programName,
creator: creator
};
}
return null;
},
type: 'ExcelPropertiesReader'
};
4. Use the new Script Include in a Business Rule or other server-side script to read the properties of an Excel file attached to a record. Here is a sample code:
javascript
var reader = new ExcelPropertiesReader();
var properties = reader.readProperties('sys_attachment_sys_id');
gs.info('Program Name: ' + properties.programName);
gs.info('Creator: ' + properties.creator);
For asking ServiceNow-related questions try this :
For a better and more optimistic result, please visit this website. It uses a Chat Generative Pre-Trained Transformer ( GPT ) technology for solving ServiceNow-related issues.
Link - nowgpt.ai
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-21-2024 09:22 PM
Thank you.
I thought it could be done using the method you described.
On the other hand, there were some points that were unclear, so I would like to ask an additional question.
I understand that I want to upload the "Apache POI Library" to ServiceNow, but how should I upload it?
I was told that I should paste it into the ScriptInclude script, but the hierarchy of the ”Apache POI Library” is complex, and I feel it is difficult to know how to upload it to the ScriptInclude.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-11-2024 12:40 AM
Hi Sourav,
Could you please give us detailed instructions for the step 1 & 2?