Creating Inbound Email Script to take an attachment and load to a existing Data Source and Transform
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-11-2023 06:09 AM
I am getting the following error :Inbound Action : did not create or update sys_data_source using current
Here is my Email Script:
(function runAction(current, event, email, logger, classifier) {
var importSetName = "my import set name";
var importSetLabel = "u_imp_my_importset_label";
var applicationScope = "my_scope";
// setup the data source
current.name = importSetName + " " + gs.nowDateTime();
current.import_set_table_name = importSetLabel;
current.import_set_table_label = importSetName;
current.type = "File";
current.format = "Excel";
current.sheet_number = 1;
current.header_row = 1;
current.file_retrieval_method = "Attachment";
current.sys_package.setDisplayValue(applicationScope);
current.sys_scope.setDisplayValue(applicationScope);
var myDS = current.insert();
new global.EmailFileImportUtils().scheduleImport(myDS);
})(current, event, email, logger, classifier);
and Here is my script include:
var EmailFileImportUtils = Class.create();
EmailFileImportUtils.prototype = {
initialize: function() {
},
scheduleImport: function(dataSourceID) {
var schRec = new GlideRecord("sys_trigger");
schRec.name = "Load Data Source: " + dataSourceID;
schRec.trigger_type = 0; // Run Once
schRec.script = "new my_scope.EmailFileImportUtils().loadImportSet('" + dataSourceID + "')";
var nextAction = new GlideDateTime();
nextAction.addSeconds(30); // 30 seconds however this can be changed.
schRec.next_action = nextAction;
schRec.insert();
},
loadImportSet: function(dataSourceID) {
// Get Datasource Record
var dataSource = new GlideRecord("sys_data_source");
dataSource.get(dataSourceID);
// Process data source file
var loader = new GlideImportSetLoader();
var importSetRec = loader.getImportSetGr(dataSource);
var ranload = loader.loadImportSetTable(importSetRec, dataSource);
importSetRec.state = "loaded";
importSetRec.update();
// Transform import set
this._doTransform(importSetRec);
},
_doTransform: function(set){
var importSetRun = new GlideImportSetRun(set.getUniqueValue());
var importLog = new GlideImportLog(importSetRun, set.data_source.name);
var ist = new GlideImportSetTransformer();
ist.setLogger(importLog);
ist.setImportSetRun(importSetRun);
ist.transformAllMaps(set);
},
type: 'EmailFileImportUtils'
};
3 REPLIES 3
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-06-2024 01:44 AM
Hi,
did you get any solution to this?
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-07-2024 02:39 PM
Yes i did
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-19-2024 06:13 AM
Please share the same. This code isn't exactly working for me.