- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2017 12:05 PM
Any help? I am doing an outbound REST call through my MID Server to get user pictures. I can verify that I get a successful response until I add a saveResponseBodyAsAttachment statement to my script. With that statement I always get the following error:
- java.net.SocketTimeoutException: connect timed out when posting to https://xxx.service-now.com/api/now/v1/attachment/file
Here is my script (with private data removed) -
var user = new GlideRecord('sys_user');
user.addQuery('xxx','xxxxxxxx');
user.query();
if(user.next()) {
try {
var token = '';
var s = new sn_ws.SOAPMessageV2('xxxxx', 'xxxxx');
s.setStringParameterNoEscape('userId', 'xxxxx');
s.setStringParameterNoEscape('credential', 'xxxxxx');
var responseS = s.execute();
var responseBodyS = responseS.getBody();
var xmlDoc = new XMLDocument(responseBodyS.toString(), true);
var token = xmlDoc.getNodeText("//authenticateReturn");
var r = new sn_ws.RESTMessageV2('User Photos', 'Get User Picture');
r.setStringParameterNoEscape('cookie', 'xxxxxx' + token);
r.setStringParameterNoEscape('xxxx', user.xxx.toString());
r.saveResponseBodyAsAttachment('ZZ_YYsys_user', user.sys_id.toString(), 'photo', 'image/jpeg');
var response = r.execute();
gs.print(response.getStatusCode());
gs.print(response.getErrorMessage());
}
catch(ex) {
gs.print('Got an exception: ' + ex.getMessage());
}
}
Solved! Go to Solution.
- Labels:
-
Integrations
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-23-2017 07:55 AM
After a lot of testing, an incident with ServiceNow, and a wireshark I found the issue. My outbound REST call uses a MID Server to get to our internal picture server. Our MID server has to use a proxy to get from the MID to our instance. What I've found is that the saveResponseBodyAsAttachment() method is attempting to go straight from the MID server to our instance. It is not using the MID server's defined proxy.
Unfortunately, there isn't a way for me to add an option or configure it to use the proxy. I've asked for a problem ticket or enhancement request from ServiceNow to have saveResponseBodyAsAttachment() use a defined proxy when a MID server is used.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2017 12:10 PM
Hi Matt,
You can try increasing the webservice timeout duration and check.
Thanks,
Vamsi
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2017 01:37 PM
Thank you for your response.
I have tried using setHttpTimeout(), waitForResponse(), and I've tried
adjusting the quota rule for REST web services. None of those things have
worked. Any other suggestions?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2017 01:46 PM
What happens if you try below
r.saveResponseBodyAsAttachment('sys_user', user.sys_id+'', 'photo','image/jpeg');
Please mark this response as correct or helpful if it assisted you with your question.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-16-2017 01:53 PM
Thank you for the suggestion. Unfortunately, I get the same result