Find your people. Pick a challenge. Ship something real. The CreatorCon Hackathon is coming to the Community Pavilion for one epic night. Every skill level, every role welcome. Join us on May 5th and learn more here.

RESTMessageV2 from business rule causes "attachment does not exist with sys_id" error

christopherjgil
Tera Guru

On a integration from one SN instance to another I am sending new attachments on insert to the other instances incident. Using a business rule. It is almost like the rest api is looking for the sys_id of the attachment on the target table instead of the source table.

I am using the following code to send the attachment:

var attachmentMessage = new sn_ws.RESTMessageV2();
         attachmentMessage.setHttpMethod("post");
        attachmentMessage.setEndpoint( "https://xxxxxxdev.service-now.com/api/now/attachment/file");
        attachmentMessage.setAuthenticationProfile("basic","de9867e9dbe0ff801acd4672399619d4");
        attachmentMessage.setQueryParameter("table_name", current.table_name);
        attachmentMessage.setQueryParameter("table_sys_id", ism_sysid);
        attachmentMessage.setQueryParameter("file_name", current.file_name);
        attachmentMessage.setRequestHeader("Content-Type", current.content_type);
        attachmentMessage.setRequestHeader("Accept", "application/json");
        attachmentMessage.setRequestBodyFromAttachment(current.sys_id);
        var response = attachmentMessage.execute();
        var responseBody = response.getBody();
        var httpStatus = response.getStatusCode();
        gs.log('attachment to be sent to ISM'+response.getBody());

I get the following error in my log:

com.glide.communications.ProcessingException: Error executing REST request: attachment does not exist with sys_id: 8b320176db3cfb001acd4672399619c9
Caused by error in sys_script.99df9784db34b3001acd4672399619ab.script at line 49

I checked the sys_id in the error and it opens the attachment on the source instance.

 

 

 

1 ACCEPTED SOLUTION

christopherjgil
Tera Guru

Sorry, I think this was resolved a couple of years ago. The sys_id was from the wrong side of the integration.  I found the correct sys_id and then the attachment was found.

View solution in original post

4 REPLIES 4

Mike Allen
Mega Sage

Just a sanity check, where is your ism_sysid variable being defined?

christopherjgil
Tera Guru

I am doing a get above in the business rule.  I have printed that and did a search on the target side to make sure it is valid.

 

Orangedrink
Tera Contributor

Try setting the when field on your business rule to after. 

christopherjgil
Tera Guru

Sorry, I think this was resolved a couple of years ago. The sys_id was from the wrong side of the integration.  I found the correct sys_id and then the attachment was found.