Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Copy Data from Excel Attachment and Paste it in a variable for a particular Catalog Item

narayansaha
Tera Contributor

Hi All,

I have a catalog item, where the end user will upload an excel file attachment.

It will automatically capture the data from the excel file and store it in a comma separated format in a variable.

How to achieve this requirement.

Any script or logic will be humbly appreciated.

Thanks and Regards,

Narayan Saha

3 REPLIES 3

athm
Tera Guru

Hi Narayan,

I think you can make use of the below API to parse the excel sheet attached by the end user.

GlideExcelParser

(https://docs.servicenow.com/bundle/kingston-application-development/page/app-store/dev_portal/API_reference/GlideExcelParserScoped/concept/GlideExcelParserScopedAPI.html)

Hope this helps you Narayan.

narayansaha
Tera Contributor

Thanks, athm!

The script looks to be a server-side script.

Need help to populate the data into a service catalog variable.

 

Regards,
Narayan Saha

sonalihanda
Tera Contributor

I got the similar Story on this  -- I have a catalog item, where the end user will upload an excel file attachment.

It will automatically capture the data from the excel file and store it in a comma separated format in a variable.

 

Script for this is :

// changes would be in HTML Template

//for copying data from excel to catalog variable separately in comma form "A, B, C"

// Please replace xyz to field name where you want this script to work

<script>
document.getElementById('xyz').addEventListener('paste', function(event) {
event.preventDefault();

// Get the pasted text
var pastedText = (event.clipboardData || window.clipboardData).getData('text');

var modifiedText = pastedText.replace(/\t+/g, ',');

// Insert the modified text into the name field
var xyzfield = document.getElementById('xyz');
var caretPosition = xyzField.selectionStart;
var currentValue = xyzField.value;
var newValue = currentValue.substring(0, caretPosition) + modifiedText + currentValue.substring(caretPosition);
xyzField.value = newValue;
});
}