Run transform map from REST API
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-22-2020 06:46 AM
I created a module where the users attaches a spreadsheet, submits the record and it kicks off a transformation. I am using the business rule below. This has worked great until we encrypted a field in the table. ServiceNow support said, "I think you can get this to work if you use a web service call with a transform map. This is because the transform map will use the same user session which make the Web Service Call." I have been looking at the REST API Explorer and cannot figure out how connect the dots to execute the transform map on an excel spreadsheet. Any advice is greatly appreciated.
// Note that the data source sys_id below is the one to which the attachment will be affixed.
var sysId=current.sys_id;
GlideSysAttachment.copy('my_table', sysId, 'sys_data_source', '<sys_id>');
// Trigger start of scheduled import:
var rec = new GlideRecord('scheduled_import_set');
rec.get('name', 'my_import_set');
gs.executeNow(rec);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2020 07:40 AM
Hi Kaniel,
i'd use something like the following
//dataSource = sys_data_source record
//transformMapIDs = sys_id of transform map
// 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
var transformWorker = new GlideImportSetTransformerWorker(importSetRec.sys_id, transformMapIDs);
transformWorker.setBackground(true);
transformWorker.start();
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2020 07:58 AM
Hi,
Since you are having an encrypted field and it will have some encryption context associated to it.
I have seen this in past that when import runs it is running as "system" user who may not have the encryption context to load the data into target table and will not load that field.
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
07-27-2020 05:57 AM
The encryption context cannot be passed to the import. It uses impersonation which is not supported by encryption.
Once the attachment is copied to the data source, I need to trigger the transform by calling the Import Set API.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-27-2020 07:51 AM
Hi Kaniel,
That seems the issue.
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader