How to create an incident along with adding an attachment via Rest API post call
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2024 04:48 AM
Hi Team,
Team,
I wrote a scripted API and trying to post the data from rest API explored, but i dont see provision to add attachement data from explorer to test the case.
May i know how to achive this?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 11:23 AM
Try adding some logging at the beginning of your script:
(function runTransformScript(source, map, log, target /*undefined onStart*/ ) {
log.info('Starting onAfter script...');
var fields = ['u_content', 'u_file_name', 'u_content_type'];
// Loop through each field
for (var i = 0; i < fields.length; i++) {
var fieldName = fields[i];
var fieldValue = source[fieldName];
// Check if the field value is empty (null or undefined)
if (gs.nil(fieldValue)) {
log.info(fieldName + ' is empty.');
} else {
log.info(fieldName + ' is not empty. Value: ' + fieldValue);
}
}
...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 06:14 PM
Hi @Sheldon Swift ,
Added the code, but don't see anything in logs. onAfter seems not triggering.
Regards,
Srinivas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-12-2024 09:23 PM
Hi @Sheldon Swift ,
I have tried with gs. log and found the log files , here are they.
u_content_type is empty.
u_content is empty.
u_file_name is empty.
Attachment data is incomplete. Skipping attachment.
I am sending the data from rest api explorer. But not pulling into transform map.
Regards,
Srinivas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-13-2024 10:14 PM
Any help please, nearing my deadline
Regards,
Srinivas

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-09-2024 11:23 AM
Duplicate post, please don't spam the forums: https://www.servicenow.com/community/developer-forum/scripted-rest-api-call-sending-attachment-along...
Please consider marking my reply as Helpful and/or Accept Solution, if applicable. Thanks!