Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

NullPointerException when record producer code trying to load import set

richard_cha
Tera Contributor

Hello I am trying to implement a record producer based on sys_data_source that will allow the automatic loading of an attached CSV file.

 

I have seen a number of other posts and web resources that suggested that the following record producer server script should be successful in doing this:

 

current.file_retrieval_method = "Attachment";
current.name = "import " + new GlideDateTime();
current.type = "File";
current.format = "CSV";
current.import_set_table_name = "x_1837147_leasem_0_bank_transactions";
current.header_row = "1";
current.sheet_number = "1";

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

var transformerWorker = new GlideImportSetTransformerWorker(importSetGR.sys_id, "a3ac083b935a431494bb70aefaba10f4");
transformerWorker.setBackground(true);
transformerWorker.start();

 

on submit this code should initialise a record in the sys_data_source table with appropriate values to allow import of a CSV file attached to the record, then  populate the import set and apply the transform map.

 

I see that the record is created in the sys_data_source table and it has the CSV file attached (as expected).

 

However the loading of the import set is not succeeding. In the log file I see the following NullPointerException error when trying to call ImportSetLoader().loadImportSetTable function:

 

 Stack trace:
 at sc_cat_item_producer.3a4b061f937a43d094bb70aefaba103e.script ➚:11
 at sys_ws_operation.4b9f0a8967101200d22b794717415a30.operation_script ➚:60 (process)
 at sys_ws_operation.4b9f0a8967101200d22b794717415a30.operation_script ➚:73
Root cause of JavaScriptException: java.lang.NullPointerException 
: java.lang.NullPointerException: Cannot invoke "com.glide.db.impex.datasource.DataSource.getLoader()" because "dataSource" is null:  com.glide.system_import_set.ImportSetLoader.loadImportSetTable(ImportSetLoader.java:51)
 com.glide.system_import_set.ImportSetLoader.loadImportSetTable(ImportSetLoader.java:45)
 java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
 java.base/java.lang.reflect.Method.invoke(Method.java:580)
 org.mozilla.javascript.MemberBox.invoke(MemberBox.java:268)
 org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:300)
 org.mozilla.javascript.ScriptRuntime.doCall(ScriptRuntime.java:3570)

 

Note this is with Australia release. Is the code I have been using no longer compatible?

Has anyone else successfully implemented a similar solution?
Any hints how to resolve the exception error?


0 REPLIES 0