Execute Script via API?

felixsigl
Kilo Explorer

Hi,

question is simple:
Is it possible to execute Script (e.g. like Script in "Scripts - Background") over SOAP or any other API?

Example: send Javascript as text via SOAP in PHP to a Servicenow instance and retrieve response text and do something with response in PHP.

Thank you

3 REPLIES 3

Daniel Draes
ServiceNow Employee
ServiceNow Employee

just to make sure I understand your question. You want to send some piece of code via SOAP and have the platform execute that code?

I believe this is possible if you write your own web service to do so. I would definitely advise not to do it as poses a big security risk as you need to be very careful what code comes in - some kind of validation what is allowed and what not is required. Otherwise code injection is very easy.

I would recommend to think about what you really need and provide dedicated web-services.


anshuman_bhatia
Giga Contributor

I wanted to do something similar to execute code from one SN instance to another.
But apparently the only way is to use inbound webservice and then pass on the encrypted string and then run it on the instance. Sending the response is possible by doing a call to a webservice on the source instance.

I believe that you would need to do something similar for your PHP application and have a webservice which will receive the response to the webservice call on SN.

Also, you can pass on a secret key which could be authenticated in the code before you run the desired script. This would allow only requests from sources which send the secret key and avoid any potential code injection concerns (not completely , but better than nothing).


adiddigi
Tera Guru

You can do it via processors. You send the text to Service Now by calling a processor, which inturn calls a Script Include. This way you will be able to run code(what ever you want to) and then return the results. check the following Script Include( this takes the input from a processor)- executes some script and returns the result in JSON format.

https://github.com/abhididdigi/JSON-Scripted-Web-Service/blob/master/JSONScriptedProcessor.js