114 views

REST Outbound Integration fails reporting 'Error constructing REST Message' 

Problem
Outbound REST Integration call fails when calling a REST Message from script but works fine when Test the related REST Message from System Web Services > Outbound > REST Message. When checking system logs, it display below error:
REST Msg Outbound - RESTMessageClient : Error constructing REST Message/Method: incident/post: com.glide.generators.InvalidGlideRecordException: REST message/method 'incident/post' not found in table 'sys_rest_message_fn': com.glide.rest.outbound.RESTMessageDAO.getMethodRecord(RESTMessageDAO.java:97)
com.glide.rest.outbound.RESTMessageDAO.<init>(RESTMessageDAO.java:72)
com.glide.rest.outbound.RESTMessageDAO.newInstance(RESTMessageDAO.java:67)
com.glide.rest.outbound.RESTMessageConfig.initNew(RESTMessageConfig.java:66)
com.glide.rest.outbound.RESTMessageClient.<init>(RESTMessageClient.java:54)
com.glide.rest.outbound.scriptable.ScriptableRESTMessageClient.<init>(ScriptableRESTMessageClient.java:56)
com.glide.rest.outbound.scriptable.ScriptableRESTMessageClient.jsConstructor(ScriptableRESTMessageClient.java:40)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
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.FunctionObject.doInvoke(FunctionObject.java:670)
org.mozilla.javascript.FunctionObject.call(FunctionObject.java:559)
org.mozilla.javascript.FunctionObject.call(FunctionObject.java:491)
org.mozilla.javascript.BaseFunction.construct(BaseFunction.java:403)
org.mozilla.javascript.ScriptRuntime.newObject(ScriptRuntime.java:2449)
org.mozilla.javascript.ScriptRuntime.newObjectEx(ScriptRuntime.java:2464)
org.mozilla.javascript.gen.null_null_script_1392._c_script_0(null.null.script:6)
org.mozilla.javascript.gen.null_null_script_1392.call(null.null.script)
org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:563)
org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3421)
org.mozilla.javascript.gen.null_null_script_1392.call(null.null.script)
org.mozilla.javascript.gen.null_null_script_1392.exec(null.null.script)
com.glide.script.ScriptEvaluator.execute(ScriptEvaluator.java:263)
com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:110)
com.glide.script.ScriptEvaluator.evaluateString(ScriptEvaluator.java:76)
com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:343)
com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:263)
com.glide.script.fencing.GlideScopedEvaluator.evaluateScript(GlideScopedEvaluator.java:250)
com.glide.processors.ScriptProcessor.evaluateScript(ScriptProcessor.java:330)
com.glide.processors.ScriptProcessor.runScript(ScriptProcessor.java:219)
com.glide.processors.ScriptProcessor.process(ScriptProcessor.java:177)
com.glide.processors.AProcessor.runProcessor(AProcessor.java:474)
com.glide.processors.AProcessor.processTransaction(AProcessor.java:199)
com.glide.processors.ProcessorRegistry.process0(ProcessorRegistry.java:178)
com.glide.processors.ProcessorRegistry.process(ProcessorRegistry.java:167)
com.glide.ui.GlideServletTransaction.process(GlideServletTransaction.java:31)
com.glide.sys.Transaction.run(Transaction.java:2037)
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
java.lang.Thread.run(Thread.java:748)

 

Cause


This is because the HTTP Method name passed from script does not match with the actual Function name which belongs to the related REST Message. In this case, the REST Message function name was Insert Incident for the corresponding HTTP Method (POST) however in script it's being used as post which does not exist and caused the trouble.

AS IT IS:

var r = new sn_ws.RESTMessageV2('incident', 'post');

TO BE:

var r = new sn_ws.RESTMessageV2('incident', 'Insert Incident');
Resolution
Correcting the REST Message function name in the source script as explained above will fix the reported issue.
Note
This is not important what name you choose for your REST Message function (sys_rest_message_fn) against the corresponding HTTP Method, the important point is you need to use the same name when invoking that REST Message function in your script. Plus, whenever you rename a REST Message function, please make sure to rename it in related scripts as well so as to avoid such issues proactively.

Article Information

Last Updated:2018-09-19 10:09:20
Published:2018-09-19