ClassCastException When Instantiating Script Include in Transform Map Script

nodisplay
Giga Contributor

Hello! I am trying to use a script include I've written to make an API call to populate a field during an import and I keep getting "Import set: ISETXXXXX transform stopped due to error: com.glide.rest.outbound.scriptable.ScriptableRESTResponse cannot be cast to com.glide.script.adaptors.WSResult" (see below for full error). The script include works elsewhere in ServiceNOW, including background scripts, workflows, and UI actions, so I don't think it's an error in there. I'm using an onBefore transform script that is very simple (see below, with sensitive data changed of course). I've included all of my various attempts at getting this to work and none of them do. The error I get is below the code example.

(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
    target.u_imported = true;

    var grCI = new GlideRecord('cmdb_ci_server');
    grCI.addQuery('name', source.u_configuration_item);
    grCI.query();
    if (grCI.next()) {
        // These work fine
        target.u_operating_system = grCI.os;
        target.u_server_assignment_group = grCI.assignment_group;
        target.u_server_support_group = grCI.support_group;

//      tried both of the below in combo with the various code attempts below these, no luck
//      gs.include('global.MyScriptInclude');
//      gs.include('MyScriptInclude');

//      var si = new MyScriptInclude();
//      gs.info('SI type: ' + typeof si);  // gives "object" but still fails

//      var si = new global.MyScriptInclude();  // Doesn't work
//      var si = new MyScriptInclude();  // Doesn't work
//      target.my_field = new MyScriptInclude().doApiCall(grCI.name); // Doesn't work
//      var my_var = new MyScriptInclude().doApiCall(grCI.name);  // Doesn't work
//      target.my_field = my_var;  // Record never gets updated/inserted
//      gs.info('my_var: ' + my_var);  // Logs the correct value returned from doApiCall() - boolean true, but still fails
//      new MyScriptInclude();  // Doesn't work

        // A test script include that just returns a string, this works
        var testSI = new test_si();
        gs.info('testSI: ' + testSI.getTestString());

        // I also tried using the sn_ws.RESTMessageV2() object to do a call manually and that works, and it's just copy/pasted from my script include.
    }

})(source, map, log, target);

My error, which gives me no clue about where in my script it's failing (though from my experimentation it seems to be when I instantiate the script include object, even though the subsequent call seems to work (see above code for example)) (Source == ImportSetTransformer, Level == Error):

Import set: ISET0044717 transform stopped due to error: com.glide.rest.outbound.scriptable.ScriptableRESTResponse cannot be cast to com.glide.script.adaptors.WSResult

java.lang.ClassCastException: com.glide.rest.outbound.scriptable.ScriptableRESTResponse cannot be cast to com.glide.script.adaptors.WSResult
at com.glide.db.impex.transformer.TransformerScript.setResponseElements(TransformerScript.java:111)
at com.glide.db.impex.transformer.TransformerScript.setStatusMessage(TransformerScript.java:95)
at com.glide.db.impex.transformer.TransformerScript.runScript(TransformerScript.java:73)
at com.glide.db.impex.transformer.TransformerScript.runWhenScript(TransformerScript.java:133)
at com.glide.db.impex.transformer.Transformer.runOnBeforeScript(Transformer.java:310)
at com.glide.db.impex.transformer.Transformer.transformBatch(Transformer.java:162)
at com.glide.db.impex.transformer.Transformer.transform(Transformer.java:88)
at com.glide.system_import_set.ImportSetTransformerImpl.transformEach(ImportSetTransformerImpl.java:304)
at com.glide.system_import_set.ImportSetTransformerImpl.transformAllMaps(ImportSetTransformerImpl.java:117)
at com.glide.system_import_set.ImportSetTransformerWorker.startWork(ImportSetTransformerWorker.java:40)
at com.glide.worker.AbstractProgressWorker.startAndWait(AbstractProgressWorker.java:126)
at com.glide.worker.ProgressWorker.startAndWait(ProgressWorker.java:52)
at com.glide.worker.BackgroundProgressJob.execute(BackgroundProgressJob.java:59)
at com.glide.schedule.JobExecutor.lambda$executeJob$0(JobExecutor.java:113)
at com.glide.schedule.JobExecutor.executeJob(JobExecutor.java:116)
at com.glide.schedule.JobExecutor.execute(JobExecutor.java:100)
at com.glide.schedule_v2.SchedulerWorkerThread.executeJob(SchedulerWorkerThread.java:300)
at com.glide.schedule_v2.SchedulerWorkerThread.lambda$process$0(SchedulerWorkerThread.java:188)
at com.glide.worker.TransactionalWorkerThread.executeInTransaction(TransactionalWorkerThread.java:35)
at com.glide.schedule_v2.SchedulerWorkerThread.process(SchedulerWorkerThread.java:188)
at com.glide.schedule_v2.SchedulerWorkerThread.run(SchedulerWorkerThread.java:102)

I've done extensive googling and cannot find anything related to this issue. Can anyone help explain this and offer a potential solution? Thank you very much!

1 ACCEPTED SOLUTION

Welp, after a bunch more testing with a lot of log statements and removing lines until I found the culprit, I humbly acknowledge that you were right. The line in my SI:

response = sm.execute();

needed to be

var response = sm.execute();

What boggles my mind is why that's not caught in the background scripts, workflows, or business rules I've used it in, but the import transform map fails because of it.

 

Anyway, thank you for your help and for pushing me to reevaluate my script include.

View solution in original post

6 REPLIES 6

Welp, after a bunch more testing with a lot of log statements and removing lines until I found the culprit, I humbly acknowledge that you were right. The line in my SI:

response = sm.execute();

needed to be

var response = sm.execute();

What boggles my mind is why that's not caught in the background scripts, workflows, or business rules I've used it in, but the import transform map fails because of it.

 

Anyway, thank you for your help and for pushing me to reevaluate my script include.

Glad you were able to find it. I agree that is very odd the background script didn't catch it.