java.lang.NullPointerException when calling \$sp.getCatalogItem

shahrin
Kilo Explorer

When using the sc_cat_item widget on existing catalog items, for more than 50% of them, I get the following error. Note that accessing them not via service portal is fine.

find_real_file.png

I then cloned the widget so I can change the code to isolate the exact line. It appears to be failing at the following line:

data.sc_cat_item = $sp.getCatalogItem(data.sys_id);

I put that in a try catch block and logged the error using the following code:

find_real_file.png ! !

The log I obtained is as follows:

Trying to get catalog item for 9c5c31ca4f66ae40014bb2f11310c787. There was an error in this widget: null:

com.glide.service_portal.variables.VariableModel.getMappedFieldLength(VariableModel.java:248)

com.glide.service_portal.variables.VariableModel.getMaxLength(VariableModel.java:225)

com.glide.service_portal.variables.VariableModel.buildVariable(VariableModel.java:190)

com.glide.service_portal.variables.VariableModel.get(VariableModel.java:80)

com.glide.service_portal.catalog.SPCatalog.getItem(SPCatalog.java:28)

com.glide.service_portal.widget.SPScriptable.getCatalogItem(SPScriptable.java:914)

sun.reflect.GeneratedMethodAccessor3975.invoke(Unknown Source)

sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

java.lang.reflect.Method.invoke(Method.java:498)

org.mozilla.javascript.MemberBox.invoke(MemberBox.java:138)

org.mozilla.javascript.NativeJavaMethod.call(NativeJavaMethod.java:292)

org.mozilla.javascript.ScriptRuntime.doCall(ScriptRuntime.java:2577)

org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:32)

org.mozilla.javascript.gen._refname__70030._c_anonymous_2(<refname>:15)

org.mozilla.javascript.gen._refname__70030.call(<refname>)

org.mozilla.javascript.ScriptRuntime.doCall2(ScriptRuntime.java:2645)

org.mozilla.javascript.ScriptRuntime.doCall(ScriptRuntime.java:2582)

org.mozilla.javascript.optimizer.OptRuntime.call0(OptRuntime.java:23)

org.mozilla.javascript.gen._refname__70030._c_anonymous_1(<refname>:2)

org.mozilla.javascript.gen._refname__70030.call(<refname>)

org.mozilla.javascript.ScriptRuntime.doCall2(ScriptRuntime.java:2645)

org.mozilla.javascript.ScriptRuntime.doCall(ScriptRuntime.java:2582)

org.mozilla.javascript.optimizer.OptRuntime.call0(OptRuntime.java:23)

org.mozilla.javascript.gen._refname__70030._c_script_0(<refname>:1)

org.mozilla.javascript.gen._refname__70030.call(<refname>)

org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:563)

org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3439)

org.mozilla.javascript.gen._refname__70030.call(<refname>)

org.mozilla.javascript.gen._refname__70030.exec(<refname>)

com.glide.script.ScriptEvaluator.execute(ScriptEvaluator.java:259)

com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:110)

com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:76)

com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:67)

com.glide.service_portal.SPScriptEvaluator.eval(SPScriptEvaluator.java:36)

com.glide.service_portal.widget.SPScriptRunner.eval(SPScriptRunner.java:202)

com.glide.service_portal.widget.SPScriptRunner.runScript(SPScriptRunner.java:83)

com.glide.service_portal.widget.SPWidget.get(SPWidget.java:109)

com.glide.service_portal.widget.SPWidget.get(SPWidget.java:92)

com.glide.service_portal.SPPage.getColumnRectangles(SPPage.java:277)

com.glide.service_portal.SPPage.getRowColumns(SPPage.java:221)

com.glide.service_portal.SPPage.getContainerRows(SPPage.java:201)

com.glide.service_portal.SPPage.getContainers(SPPage.java:188)

com.glide.service_portal.SPPage.getPage(SPPage.java:98)

com.glide.service_portal.SPPage.get(SPPage.java:55)

com.glide.service_portal.SPRestService.page(SPRestService.java:43)

sun.reflect.GeneratedMethodAccessor4024.invoke(Unknown Source)

sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

java.lang.reflect.Method.invoke(Method.java:498)

com.glide.rest.handler.impl.ServiceHandlerImpl.invokeService(ServiceHandlerImpl.java:43)

com.glide.rest.processors.RESTAPIProcessor.process(RESTAPIProcessor.java:228)

com.glide.processors.AProcessor.runProcessor(AProcessor.java:424)

com.glide.processors.AProcessor.processTransaction(AProcessor.java:195)

com.glide.processors.ProcessorRegistry.process0(ProcessorRegistry.java:178)

com.glide.processors.ProcessorRegistry.process(ProcessorRegistry.java:167)

com.glide.ui.GlideServletTransaction.process(GlideServletTransaction.java:49)

com.glide.sys.Transaction.run(Transaction.java:1976)

java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)

java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)

java.lang.Thread.run(Thread.java:745)

My suspicion is that it is just a service portal java function issue (as other ways of accessing the form are all okay. Only in portal widgets do we see this problem)

Any help would be much appreciated.

Many thanks in advance. !

11 REPLIES 11

BALAJI40
Mega Sage

To get the sys_id in service portal, $sp.getParameter("sys_id").


Instead of that line change with above line.


Hi balajireddy.



I already have the following code, just not shown in the screenshot above.


var cat_sys_id = $sp.getParameter("sys_id").



Also as mentioned in the code above, sys_id is retrieved successfully and stored in variable cat_sys_id. This is proven by the following line:


gs.error("Trying to get catalog item for " + cat_sys_id + ". There was an error in this widget",e)


which outputs this line in the logs which clearly shows cat_sys_id has the correct sys_id value.


Trying to get catalog item for 9c5c31ca4f66ae40014bb2f11310c787. There was an error in this widget: null:


saurabh1
Giga Contributor

Hi Shahrin Shahrulzaman,



Did you find any solution ? I am also facing the same issue.


sujanmattaparth
Tera Contributor

Hi All,



In my case, I removed all the variables and variable sets associated to the catalog item.


For my requirement, i don't need variables. $sp.getCatalogItem method causing slowness in the page so I moved everything to widgets which resolved my issue.


My requirement may be different from yours. But for some reason variables causing the issue. Not sure whether this is appropriate but that's what I found finally.