Sending attachment from one ServiceNow instance to other fails

Gowri S
Tera Expert

Hi,

When I try to attach file in incident, file should get attached in other incident. 

So on first instance, written a business rule to trigger outbound Attachment API - Post method. With below script.

outbound API URL: https://dev**.service-now.com/api/now/attachment/upload

Script:

var file = 'https://dev****.service-now.com/api/now/attachment/'+current.sys_id;

  var r = new sn_ws.RESTMessageV2('SendAttachment', 'sendIncAttachment');
  r.setStringParameter('table_name',current.table_name.toString());
  r.setStringParameter('table_sys_id',current.table_sys_id.toString());
  r.setStringParameter('file_name',current.file_name.toString());
r.setStringParameter('uploadFile',file);
 
var response = r.execute();
gs.log("GS ATTACHMENT Response status:" + response.getStatusCode());
gs.log("GS ATTACHMENT Response:" + response.getBody());
 
But getting error as below
GowriS_0-1689258079827.png

 

Could you please help to resolve this issue. Thanks.

1 ACCEPTED SOLUTION

sushantmalsure
Mega Sage
Mega Sage

based on your comment on other thread.

Response:{"error":{"message":"User not authorized","detail":"User is unauthorized to write to record: incident.a83820b58f723300e7e16c7827bdeed2"},"status":"failure"}

 

This is happening because the user you are using for attachment transfer does not have sufficient roles to write incident record. Try user with admin role for testing .

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

View solution in original post

2 REPLIES 2

sushantmalsure
Mega Sage
Mega Sage

based on your comment on other thread.

Response:{"error":{"message":"User not authorized","detail":"User is unauthorized to write to record: incident.a83820b58f723300e7e16c7827bdeed2"},"status":"failure"}

 

This is happening because the user you are using for attachment transfer does not have sufficient roles to write incident record. Try user with admin role for testing .

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

@manju12 , @sushantmalsure , Thanks a lot, it worked.