Import data via a Record producer and generate/ display a message on the screen with detailed results of how many records are inserted / ignored/updated

Adithi2
Tera Contributor

Hello,

I want to import data from external file expected it would be excel file. This I have implemented using the record producer where solution enables users to submit a record producer with an attached excel document which generates a data source and triggers one or many transform maps. Below is the script used in record producer:

I have two queries here:

1. Following a successful transform, message must be displayed on the screen containing the results of their transforms like how many records are inserted / updated / ignored etc.. I do not want email notification, I just want a simple message to be displayed on the screen

2. I see  this code will generate data source every time. I need to use the same data source all the time with the latest attachment.

Please assist on this.

var transformMapSysIDs= 'bedc1fb21b909d5085eb64a2604bcbea';
current.name = gs.getUserName() + " User Import at: " + new GlideDateTime();
current.import_set_table_name = 'u_mass_multimedia_device'; //name of import set table
current.file_retrieval_attachment =  "Attachment";
current.type = "File";
current.format = "Excel";
current.header_row = 1;
current.sheet_number =1;
current.insert(); // Need this to load & transform directly

//Time to load excel file into import table

var loader = new GlideImportSetLoader();
var importSetRec = loader.getImportSetGr(current);
var ranload = loader.loadImportSetTable(importSetRec, current);
importSetRec.state = "loaded";
importSetRec.update();

//Time to run transform with transform map
var transformWorker = new GlideImportSetTransformerWorker(importSetRec.sys_id,transformMapSysIDs);
transformWorker.setBackground(true);
transformWorker.start();

gs.addInfoMessage("Your import file has been submitted.");

//To avoid to create another data source we abort RP insert
current.setAbortAction('true');

---------------------------------------------------------------------------------------------------------------------------------------------

 

 

Thanks

Adithi

6 REPLIES 6

asifnoor
Kilo Patron

Hi,

I think this line might be creating a datasource everytime. Rather than this, you already create 1 data source and update that with your script.
current.sheet_number =1;
current.insert(); 

Mark the comment as a correct answer and helpful if this helps.

Adithi2
Tera Contributor

Hi,

I created data source & updated the below script (which I found in Now community itself) in record producer. I'm not sure how the script is working & the use of Scheduled import set. 

Can you please assist on this ?

 

var dataSourceSysId = '3025e6e81b24591485eb64a2604bcb95 '; //Data source sys_id

var attID = new GlideRecord('sys_attachment');
attID.get('sys_id'); // Attachment record sys_id

//Delete existing attachment from data source
var sourceID = new GlideRecord("sys_data_source");
if(sourceID .get(dataSourceSysId)){
var attach = new GlideSysAttachment();
attach.deleteAll(sourceID );
}


var attachRef= new GlideSysAttachment();
attachRef.writeContentStream(sourceID ,attID.getValue("file_name"), attID.getValue("content_type"), attachRef.getContentStream(attID.getUniqueValue()));

// var schImp_GR = new GlideRecord('scheduled_import_set');
// schImp_GR.addQuery('data_source',dataSourceSysId);
// schImp_GR.query();
// if(schImp_GR.next()){
// SncTriggerSynchronizer.executeNow(schImp_GR);
// }

var transformMapSysIDs= 'bedc1fb21b909d5085eb64a2604bcbea';

//Time to load excel file into import table

var loader = new GlideImportSetLoader();
var importSetRec = loader.getImportSetGr(current);
var ranload = loader.loadImportSetTable(importSetRec, current);
importSetRec.state = "loaded";
importSetRec.update();

//Time to run transform with transform map
var transformWorker = new GlideImportSetTransformerWorker(importSetRec.sys_id,transformMapSysIDs);
transformWorker.setBackground(true);
transformWorker.start();

gs.addInfoMessage("Your import file has been submitted.");

//To avoid to create another data source we abort RP insert
current.setAbortAction('true');

 

Thanks

Adithi