Validating Uploaded Excel & CSV Templates in ServiceNow with Flow Designer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
2 hours ago
Validating Uploaded Excel & CSV Templates in ServiceNow with Flow Designer
When end-users upload files in ServiceNow (through Catalog Items or forms), the files often need to match a specific template. Validating uploaded files before import prevents bad data, incomplete loads, and rework.
This article explains how to:
- Extract column headers from uploaded Excel or CSV files.
- Compare them with expected template headers.
- Close the request as Incomplete if the template doesn’t match.
Flow Setup
The flow contains these steps:
- Trigger → Service Catalog request.
- Look Up Attachments → Get both uploaded and template files.
- Custom Flow Actions:
- Extract Excel headers
- Extract CSV headers
- Validate headers
- Decision Branch → Continue if valid, stop if invalid.
Here’s a simplified view of the flow:
Trigger (Catalog Item)
↓
Look up uploaded attachment
Look up template attachment
↓
Extract headers (Excel or CSV)
↓
Validate headers
↓
[If Invalid] Close Request as Incomplete
[If Valid] Continue Import/Data Source
Flow Action 1: Extract Excel Headers
This action uses GlideExcelParser to fetch headers from an uploaded Excel file (.xlsx).
(function execute(inputs, outputs) {
var parser = new sn_impex.GlideExcelParser();
var attachment = new GlideSysAttachment();
var attachmentStream = attachment.getContentStream(inputs.attachment);
parser.parse(attachmentStream);
var headers = parser.getColumnHeaders();
var resultOutput = [];
headers.forEach(function(ele){
resultOutput.push(ele);
});
outputs.headers = resultOutput.toString();
})(inputs, outputs);
What it does:
- Reads the Excel file.
- Extracts the first row as headers.
- Returns headers as a comma-separated string.
Flow Action 2: Extract CSV Headers
This action handles .csv files using GlideTextReader.
(function execute(inputs, outputs) {
var attachment = new GlideSysAttachment();
var attachmentStream = attachment.getContentStream(inputs.attachment);
// Read the CSV file
var reader = new GlideTextReader(attachmentStream);
// First line should be the header row
var line = reader.readLine();
var headers = [];
if (line) {
headers = line.split(";").map(function(h) {
return h.trim();
});
}
outputs.headers = headers.toString();
})(inputs, outputs);
What it does:
- Reads the first line of a CSV.
- Splits it by ; (configurable if your delimiter differs).
- Returns headers as a string.
Flow Action 3: Validate Template
This action checks if all expected fields exist in the uploaded file.
(function execute(inputs, outputs) {
var headers = inputs.uploaded_doc_headers.toLowerCase().split(',');
var fields = inputs.template_headers.toLowerCase().split(',');
var valid = true;
fields.forEach(function(field) {
if (!headers.includes(field)) {
valid = false;
}
});
outputs.is_valid = valid;
})(inputs, outputs);
What it does:
- Compares uploaded headers with template headers.
- Returns true if all fields are present, false if not.
Flow Logic
- If is_valid = true → Continue with import or processing.
- If is_valid = false →
- Mark request as Closed Incomplete.
- Stop further processing.
- (Optional) Notify requester with details of missing fields.
Why This Matters
- Works with both Excel and CSV uploads.
- Prevents invalid data from entering staging or target tables.
- Provides early validation and clear feedback to users.
- Fully configurable (delimiter, expected headers, error handling).
Have questions or want to share your approach? Drop your thoughts in the comments!
- 27 Views