How to use custom .JAR Mid server packages?

Rushit Patel2
Tera Guru

Hi all,

i uploaded my custom jar as per this page MID Server - ServiceNow Wiki   but it doesnot say how to use it. can any one help?

The jar is uploaded to the extlib folder using the JAR Files module. When I call the methods in the package using the Javascript Probe, I get the output in the ECC queue as :

TypeError: [JavaPackage org.demo.test] is not a function.

However, when I place the jar in the lib folder and invoke the package call using the Javascript Probe, I get the proper results in the ECC queue.

Can you please help me what needs to be done to make the packages call work for the jar placed in extlib folder ?

12 REPLIES 12

ofaura
ServiceNow Employee
ServiceNow Employee

Thanks Dave, I have tested following on the javascriptProbe:



03.png



But not luck, I got the same result, output is empty.


Dave Smith1
ServiceNow Employee
ServiceNow Employee

.. because you need to do something with the output.



Try: document.write(returnValue) or ms.log("The value is:" + returnValue) - something that writes it out, rather than holds it within JavaScript.


ofaura
ServiceNow Employee
ServiceNow Employee

Hi Dave,



I have tested ms.log("The value is:" + returnValue) and it ´s showed on the MID Server log, but still the /output tag is empty.



Best regards,


gcubed_
Tera Contributor

In your JavascriptProbe the return should be the last javascript object referenced.  



So try:



var doSomething = new Packages.com.reed.mid.DoSomething(); var returnValue = doSomething.doIt(); ms.log('Hello World'); returnValue;



On a side note:



If you include these imports in your java classes:



import com.snc.core_automation_common.logging.Logger;


import com.snc.core_automation_common.logging.LoggerFactory;



and define a logger:



private static final Logger log = LoggerFactory.getLogger(ProjectHelper.class);


     


Then your log messages in you custom jar will should up in the agent.log.



The other thing I to do is setup a development mid server on the box you are developing on.   Update the wrapper-override.conf and enable JDP which allows you to debug your code with the ServiceNow instance providing triggering of running your methods.




V/r,


Gene


ofaura
ServiceNow Employee
ServiceNow Employee

Hi Gene,



Thanks for your suggestion.   I will use the logger on the MID Server, really useful!



I have found that </output> tag was empty because I call to the probe as follows:



  jspr.setJavascript("var doSomething = new Packages.com.reed.mid.DoSomething(); doSomething.doIt();ms.log('Hello World');");



I have moved ms.log before the call to the JAR:



  jspr.setJavascript("var doSomething = new Packages.com.reed.mid.DoSomething();ms.log('Hello World');doSomething.doIt();");



Now the <Output> has the message from the JAR file!



Best regards,



Oscar