Need to create attachment with same sys_id in target instance
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2024 07:28 AM
I am trying to create attachment with same sys_id in target instance as of source instance using Attachment API but getting error, Please suggest any method how we can achieve this requirement.
BR on Kb_knowledge table
After Update
(function executeRule(current, previous /*null when async*/ ) {
try {
gs.info("kb_attachment_ebond");
var attach = new GlideRecord("sys_attachment");
attach.addQuery("table_sys_id", current.sys_id);
attach.addQuery("table_name", "kb_knowledge");
attach.query();
while (attach.next()) {
var fileName = attach.file_name.getValue();
var tablesysid = current.u_correlation_display.getValue();
var attachmentsysid = attach.sys_id.getValue();
var attachment = new sn_ws.RESTMessageV2();
attachment.setHttpMethod('POST');
var username = "XXXXX";
var password = "XXXXX";
attachment.setBasicAuth(username, password);
attachment.setRequestHeader("Accept", "application/json, text/plain, */*");
attachment.setRequestHeader('Content-Type', 'image/png');
attachment.setQueryParameter("file_name", fileName);
attachment.setQueryParameter("table_name", "kb_knowledge");
attachment.setQueryParameter("table_sys_id", tablesysid);
attachment.setRequestBodyFromAttachment(attachmentsysid);
var response = attachment.execute();
var requestBody = response.getRequestBody();
var responseBody = response.getBody();
var httpStatus = response.getStatusCode();
gs.info("check_status: " + httpStatus);
gs.log("kb_e-bondingattachment_request" + requestBody);
gs.log("kb_e-bondingattachment_response" + responseBody);
}
} catch (ex) {
var message = ex.message;
}
})(current, previous);
1 REPLY 1
Options
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-08-2024 08:55 AM
Hi @amit71 ,
Please try below approach:
If I could help you with your Query then, please hit the Thumb Icon and mark it as Correct !!
Thanks & Regards,
Sumanth Meda