Creating records from excel using transform map
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-11-2024 03:43 AM - edited 11-11-2024 03:53 AM
Hi,
I have a custom table and when someone is uploading an excel and creating a record i want to read the excel and create records in another table. I am able to achieve this already with the current script but i need to use transform map and import set to do the same. I want to now make records in the staging table now after reading the excel and with transform map that i have already created I want to create records in my target table. What changes I need to do in the script or is there any different script in need to write? The user will not be able to use the import excel functionality.
(function executeRule(current, previous /*null when async*/ ) {
var sys = '';
var gr = new GlideRecord('sys_attachment');
gr.addQuery('table_sys_id', current.sys_id);
gr.query();
if (gr.next()) {
sys = gr.sys_id;
}
var parser = new sn_impex.GlideExcelParser();
var attachment = new GlideSysAttachment();
var attachmentStream = attachment.getContentStream(sys);
parser.setSource(attachmentStream);
var list_sheet_name = parser.getSheetNames();
for (var i = 0; i < list_sheet_name.length; i++) {
if (parser.parse()) {
var headers = parser.getColumnHeaders();
var header1 = headers[0];
var header2 = headers[1];
var header3 = headers[2];
while (parser.next()) {
var row = parser.getRow();
var inc = new GlideRecord('x_iem_rail_ops_na_rail_route');
inc.initialize();
inc.setValue('route_unique_id', row[header1]);
inc.setValue('route_type', row[header2]);
inc.setValue('route_missing_values', row[header3]);
inc.setValue('rail_request_number', current.parent);
inc.insert();
}}
})(current, previous);