- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2020 02:02 AM
Issue : Imports set shows error 'No transform entry or scripts are defined'.
Steps 1. Create request and add csv file
2. run the data source for received CSV via REQUEST
3. Transform attachment - csv file details to Target table
1. created a catalog item : import tasks
2. Data source- 'FJ - Fragomen Import and Transform map - FJ TM - Fragomen Case created
3. created script include- to run data source on creation of RITM(import task)
3.1 FJ_ImportProcessorAutomated
gs.include('FJ_StringUtil');
var FJ_ImportProcessorAutomated = Class.create();
FJ_ImportProcessorAutomated.prototype = {
initialize: function() {
this.extractFieldList = [
'sys_created_on',
'sys_import_row',
'sys_import_state',
'sys_row_error',
'sys_import_state_comment',
['sys_import_set', 'number'],
['sys_target_sys_id', 'number']
];
this.dataSource = 'FJ - Fragomen Import';
},
performImport: function(current) {
try {
this._removeExistingAttachment();
this._copyAttachment(current);
var res = this._initiateDataLoad(current);
return res;
} catch(error) {
gs.error('Error in Script Include FJ_ImportProcessorAutomated - performImport-' + error);
}
},
/*_________________________________________________________________
* Description: Used for validation of choice values before inserting during Data imports
* Parameters: Table Name and Choice Label
* Returns: Choice Value if present, else keyValue
* Note: Please use getDisplayValue() if you already have a reference to the target table
________________________________________________________________*/
getChoiceLabel: function(tableName, fieldName, keyValue) {
var res = '';
var grC = new GlideRecord('sys_choice');
grC.addQuery('name', tableName);
grC.addQuery('element', fieldName);
grC.addQuery('value', keyValue);
grC.addActiveQuery();
grC.query();
if(grC.next()) {
res = grC.label.toString();
} else {
res = keyValue;
}
return res;
},
/*_________________________________________________________________
* Description: Checks if a table state transition from existing value to new value is valid as per the business process of BCH
* Parameters: Table name, New state, Existing state
* Returns: TRUE or FALSE
* Note: newState needs to be a Choice Label value
________________________________________________________________*/
checkValidStateTransition : function(tableName, existingState, newState) {
var res = false;
// tableName has not yet been configured as it is always Incident in this case.
existingState = parseInt(existingState, 10);
var incident = {
1:// New
['new','in progress','canceled'],
2:// In Progress
['in progress','on hold','resolved','canceled'],
3:// On Hold
['on hold','in progress'],
6:// Resolved
['resolved','in progress'],
7:// Closed
[],
8:// Cancelled
[]
};
if(incident[existingState].toString().indexOf(newState) > -1) {
res = true;
}
return res;
},
/*_________________________________________________________________
* Description: Check if any given user belongs to a group. This is required for transform map check to prevent users being assigned to incidents if they do not belong to a group.
* Parameters: group name and user ID
* Returns: TRUE/FALSE
________________________________________________________________*/
checkUserGroupMembership: function(groupName,userID) {
var res = false;
var groupFlag = false;
var userFlag = false;
// Check if Group is valid
var grGrp = new GlideRecord('sys_user_group');
grGrp.addQuery('name', groupName);
grGrp.addActiveQuery();
grGrp.query();
groupFlag = grGrp.next();
// Check if User is valid
var grUser = new GlideRecord('sys_user');
grUser.addQuery('user_name', userID);
grUser.addActiveQuery();
grUser.query();
userFlag = grUser.next();
if(groupFlag && userFlag) {
// Check if user is a member of the group
var grMember = new GlideRecord('sys_user_grmember');
grMember.addQuery('group', grGrp.getUniqueValue());
grMember.addQuery('user', grUser.getUniqueValue());
grMember.query();
res = grMember.next();
}
return res;
},
_removeExistingAttachment: function() {
//Remove existing Attachments if present on the Data Source, before proceeding to Import
var grGetAttach = new GlideRecord('sys_attachment');
grGetAttach.addQuery('table_name', 'sys_data_source');
grGetAttach.addQuery('table_sys_id', this.dataSource); // sys_id of the Data Source
grGetAttach.query();
while (grGetAttach.next()) {
var grRemoveAttachment = GlideSysAttachment();
grRemoveAttachment.deleteAttachment(grGetAttach.sys_id); // Delete Attachments on the Data Source
}
},
_copyAttachment: function(reqItem) {
var copyAttach = new GlideSysAttachment();
copyAttach.copy('sc_req_item', reqItem.sys_id, 'sys_data_source', this.dataSource);
},
_initiateDataLoad: function(current) {
//load(/* Data Source */ , /* Transform Map */ )
// var res = new FJ_AutomatedDataLoad().load(gs.getProperty('fj.fragomen.data.source.name','FJ - Fragomen Import'), gs.getProperty('fj.fragomen.transform.map','FJ TM - Fragomen Case'));
var res = new FJ_AutomatedDataLoad().load('FJ - Fragomen Import','FJ TM - Fragomen Case');
return res;
},
_logErrors: function(res) {
var exportSet = [];
var exportStr = '';
// Generate the Output file with Error Log
if (JSUtil.notNil(res)) {
exportSet = this._retrieveRecords(res);
var crlf = '\n';
exportStr = exportSet.join(crlf);
}
return exportStr;
},
_retrieveRecords: function(queryString) {
var res = [];
res.push(this._extractFieldList());
var grOutputError = new GlideRecord('sys_import_set_row');
grOutputError.query('sys_import_set', queryString);
grOutputError.orderBy('sys_import_row');
grOutputError.query();
while (grOutputError.next()) {
res.push(this._getCSVRow(grOutputError));
}
return res;
},
_extractFieldList: function() {
var res = [];
var elements = this.extractFieldList.length;
for (var index = 0; index < elements; index++) {
res.push(this._getElement(this.extractFieldList[index]));
}
return res;
},
_getElement: function(element) {
var res = '';
var xtype = JSUtil.typeOf(element);
if (xtype == 'string') {
res = element;
} else if (xtype == 'array') {
res = element[0] + '';
}
return res;
},
_getCSVRow: function(grOutputError) {
var res = [];
var cnt = this.extractFieldList.length;
for (var i = 0; i < cnt; i++) {
res.push('"{0}"'.format(this._getFieldContent(grOutputError, i)));
}
return res.join();
},
_getFieldContent: function(grOutputError, index) {
var res = '';
var xtype = JSUtil.typeOf(this.extractFieldList[index]);
if (xtype == 'string') {
res = grOutputError.getDisplayValue([this.extractFieldList[index]]) ? grOutputError.getDisplayValue([this.extractFieldList[index]]) : '';
} else if (xtype == 'array') {
res = this._getFieldArrayContent(grOutputError, this.extractFieldList[index]);
}
return res;
},
_getFieldArrayContent: function(grOutputError, fieldArray) {
try {
var res = '';
var elements = fieldArray.length;
res = grOutputError.getDisplayValue([fieldArray[0]]) ? grOutputError.getDisplayValue([fieldArray[0]]) : '';
if (elements > 0) {
//for (var eleIndex = 1; eleIndex <= elements; eleIndex++) {
res = grOutputError[fieldArray[0]][fieldArray[1]] ? grOutputError[fieldArray[0]][fieldArray[1]] : '';
//}
}
return res;
} catch (error) {
gs.error('Error in Script Include FJ_ImportProcessorAutomated - _getFieldArrayContent-' + error);
}
},
_createAttachment: function(current, content) {
var grAttachment = new GlideSysAttachment();
grAttachment.write(current, current.number + '-Fragomen Case Update Log-' + gs.nowDateTime().toString().replace(/:/g, '-') + '.csv', 'text/csv', content);
},
type: 'FJ_ImportProcessorAutomated'
};
2.2 FJ_AutomatedDataLoad -- to run data source
gs.include("PrototypeServer");
var FJ_AutomatedDataLoad = Class.create();
FJ_AutomatedDataLoad.prototype = {
initialize: function() {},
load: function( /* Data Source */ source, /* Transform Map */ mapName) {
var res = this._load(source, mapName, false);
return res;
},
_load: function( /* Data Source */ source, /* Transform Map */ mapName, /* Delete Transform Map */ cleanMap) {
var sourceGr = new GlideRecord('sys_data_source');
sourceGr.addQuery('name', source);
sourceGr.query();
// if we have our data source continue
if (!sourceGr.next()) {
// gs.print('Did not find Data Source ' + source);
return;
}
var map = new GlideRecord('sys_transform_map');
map.addQuery('name', mapName);
map.query();
// if we have a map we can now load and run the transform
if (!map.next()) {
gs.print('Did not find Transform map ' + mapName);
return;
}
// gs.print('Loading Import Set ' + source);
var loader = new GlideImportSetLoader();
var importSetGr = loader.getImportSetGr(sourceGr);
var ranload = loader.loadImportSetTable(importSetGr, sourceGr);
if (!ranload) {
// gs.print('Failed to load import set ' + source);
return;
}
//gs.print('Running Transform map ' + map.name);
var t = new GlideImportSetTransformer();
t.setMapID(map.sys_id);
t.transformAllMaps(importSetGr);
// gs.log('Import Set SYS ID--' + importSetGr.sys_id);
// gs.log('Import Set Reference--' + importSetGr);
return importSetGr.sys_id;
}
};
Solved! Go to Solution.
- Labels:
-
Service Catalog
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2020 03:47 AM
Hi,
can you try to hard-code the sys_id of transform map
it seems you are having multiple transform maps with same name
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2020 03:15 AM
Hi,
please try to add debug statements in this function
Also what error you received?
Is this the 1st time you are running this? if not then when was the last time you ran it successfully?
Is the file being attached to data source a valid file extension expected by data source?
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2020 03:15 AM
throws error - in system logs
No transform entry or onStart/onBefore is defined. Skip all row transforms. | I |
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2020 03:17 AM
Hi,
It seems it is unable to locate the transform map during the execution
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2020 03:35 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2020 03:36 AM
is there issue with map.sys_id??