A Script Include to cater to Scripted Web services, using JSON over REST.
JSON Scripted Web Service consists of all the parts that one would need to write Scripted Web Service code for REST (instead of SOAP). If you already have worked with Scripted WebServices for SOAP, this Script Include is same concept extending it to REST .
You can write code in the Script Part of JSON Scripted WebService Module(just same as how you write it for Scripted Web Service), which will be executed,and the results(in JSON) will be passed to the caller of that Web Service.
- A table where you can write the Code that you want to execute.
- A Script Include that takes the Script that you have written, executes the code and passes the result to the caller.
Install the Update Set JSONScriptedWebServices update set from the Update Set folder.
Once you install that Update Set, You will be greeted with a new module called ** Scripted JSON Web Service ** and a new Script Include called ** JSONScriptedProcessor **
Go to Scripted JSON Web Service , Click on new (which opens a new record) which has two columns:
- END Point URL - The URL to which the Caller,calling this Web Service will
POST. !important Note that, this is the value you will be using to setsysparm_scriptedNamein the URL(below) - The Script which you would want to run. Remember, this script should ** always ** have a
returnstatement, and it always should returnJSON
This variable that you return will be passed back to the caller.
Once you are done writing your script - Click on Submit or Save. Notice that once you Save/Submit there will be a couple of lines that will be added to the Script. Please don't modify those lines, unless you know what you're doing.
You can call any JSON Scripted Web Service over REST using this URL:
https://[your_instance].service-now.com/ScriptedJSON.do?sysparm_raw=true&sysparm_scriptedName=[name_of_the_scripted_service_created_in_step_1]
The headers should be set to use Basic Authentication.
The parameters should be passed as body of this REST request. Remember, the parameter should always be in JSON format.
The Parameter will be available to the Script of JSON Scripted Web service as request object. See the TEST CASES folder for examples and screens.
* Add JSONParser to check if the JSON that is being received and Sent is a valid JSON, else raise an error
Use JSUTil2's Validate JSON to validate the input and the output JSON. The script in this Script Include isn't updated.
- Add a check so that only the user with a read permission can execute the queries.
- For installation of Update Sets please visit this WIKI LINK
A Note about MemLeak issue #1 : #1
If you are facing a MemLeak issue just like Wobloz, try using the Script present in the Branch : Issue-#1---Memory-Leak. I'm hoping that should fix the issue.
- To user CAPAJC for this post, and my friend and collegue Mohammed Ishaq for asking the question.