The CreatorCon Call for Content is officially open! Get started here.

Run transform map from REST API

Kaniel Battles
Tera Contributor

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);		
4 REPLIES 4

Kieran Anson
Kilo Patron

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();

Ankur Bawiskar
Tera Patron
Tera Patron

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

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

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. 

 

Hi Kaniel,

That seems the issue.

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader