RESTMessageV2 API can be used directly from the instance, or via a MID Server. When used via a MID Server that is configured to connect to the instance via a Proxy, the .saveResponseBodyAsAttachment() method doesn't work.
This is because the code in the mid server calls an instance REST API directly, without going via the Proxy.
The MID Server agent log would give an error like this:
05/19/17 10:47:54 (211) Worker-Standard:MIDWorker WARNING *** WARNING *** java.net.SocketTimeoutException: connect timed out when posting to https://INSTANCE_NAME.service-now.com/api/now/v1/attachment/file
05/19/17 10:47:54 (211) Worker-Standard:MIDWorker Enqueuing: C:\ServiceNow MID Server\agent\work\monitors\ECCSender\output_2\ecc_queue.e731ee0a4f327a04037c495d0210c7e2.xml
05/19/17 10:47:54 (211) Worker-Standard:MIDWorker Worker completed: RESTProbe source: https://XXXXXX time: 0:00:10.188
Steps to Reproduce
- Set up a MID Server to connect to the instance via a Proxy
- Create a script that uses RESTMessageV2 via a MID Server like the example in the Documentation.
- Before .execute(), run saveResponseBodyAsAttachment() as per the documentation of that method of the API
- Run that script from 'Scripts - Background.
- The ecc_queue output and input will be seen, but no attachment will be created in the instance.
This is Fixed from the London version and later. Please upgrade.
For earlier versions, use one of these alternatives:
- Use a MID Server that connects to the instance without a proxy.
- Make the REST request straight from the instance, without going via a MID Server.
Related Problem: PRB1028554