- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2022 10:25 AM
Hi,
I get a response file through RestMessage call. Next I copy this response in CSV file as attachment in a data source record already created. Then I need check the response in log and execute the data source and transform map with script.
var req = new sn_ws.RESTMessageV2('rest_name', 'method_name');
req.saveResponseBodyAsAttachment('target_table', 'sys_id_record', 'file_name.csv');
var response = req.execute();
response.waitForResponse(500);
gs.info('&&&Test response \n' + response.getBody());
// Trigger data source and transform map with script
The problem is if I copy the csv file through saveResponseBodyAsAttachment the next part of my code doesn't execute.
If I comment the line req.saveResponseBodyAsAttachment('target_table', 'sys_id_record', 'file_name.csv') and attach the .csv file to the data source manually, when I execute the code, I can see in log the response, response.getBody(), and the part of code that I named in the code above like "Trigger data source and transform map with script" works perfectly.
Why the method saveResponseBodyAsAttachment stop everthing after it in my code?
There is some way to solve this or another solution with script code?
Thanks in advance
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2022 04:56 AM
I found the problem.
In gs.info('&&&Test response \n' + response.getBody()); getBody() is not supported.
That was the error!

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2022 11:04 AM
I think it should be below, check this article:
https://developer.servicenow.com/blog.do?p=/post/saving-restmessagev2-responses-as-attachments/
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-05-2022 03:20 PM
Thanks for your answer Joro!
I checked this article before I need attach the response on another record.
I understand that code. In my case, saveResponseBodyAsAttachment works perfectly, with this method I achieve save the response with a csv file in the data source record. But the code below saveResponseBodyAsAttachment doesn't execute and I don't understand why.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2022 03:52 AM
May be try this way?
var req = new sn_ws.RESTMessageV2('rest_name', 'method_name');
//req.saveResponseBodyAsAttachment('target_table', 'sys_id_record', 'file_name.csv');
var response = req.execute();
response.waitForResponse(500);
req.saveResponseBodyAsAttachment('target_table', 'sys_id_record', 'file_name.csv');
gs.info('&&&Test response \n' + response.getBody());
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-07-2022 04:57 AM
Thanks a lot, Joro!