Attachment for soap via webservice
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2023 03:40 AM
Hi,
I have tired diffrent solutions for Attachements for via web service. I have written BR for this
Please go through it get the crt solution for this
Thanks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2023 04:53 AM
I hope this helps -
(function executeRule(current, previous /*null when async*/ ) {
// check if the incident already exists on the other system
var s = new sn_ws.SOAPMessageV2('Lemongrass', 'getRecords');
s.setStringParameterNoEscape('getRecords.number', current.number);
var response = s.execute();
var ResponseBody = response.getBody();
var status = response.getStatusCode();
var xmlDoc = new XMLDocument2();
xmlDoc.parseXML(ResponseBody);
var num = xmlDoc.getNodeText('//number');
var sysId = xmlDoc.getNodeText('//sys_id');
gs.addInfoMessage(status);
gs.addInfoMessage(num);
if (num) {
// Updating the record if the record already exists in the other system
var s2 = new sn_ws.SOAPMessageV2('Lemongrass', 'update');
s2.setStringParameterNoEscape('update.sys_id', sysId);
s2.setStringParameterNoEscape('update.short_description', current.short_description);
s2.setStringParameterNoEscape('update.resolved_by', current.resolved_by);
s2.setStringParameterNoEscape('update.sys_id', sysId);
s2.setStringParameterNoEscape('update.resolved_at', current.resolved_at);
s2.setStringParameterNoEscape('update.urgency', current.urgency);
s2.setStringParameterNoEscape('update.closed_by', current.closed_by);
s2.setStringParameterNoEscape('update.hold_reason', current.hold_reason);
s2.setStringParameterNoEscape('update.caller_id', current.caller_id);
s2.setStringParameterNoEscape('update.category', current.category);
s2.setStringParameterNoEscape('update.close_notes', current.close_notes);
s2.setStringParameterNoEscape('update.close_code', current.close_code);
if (current.state == '6' || current.state == '7' || current.state == '8')
s2.setStringParameterNoEscape('update.state', '7');
else
s2.setStringParameterNoEscape('update.state', current.state);
s2.setStringParameterNoEscape('update.impact', current.impact);
s2.setStringParameterNoEscape('update.number', current.number);
s2.setStringParameterNoEscape('update.active', current.active);
s2.setStringParameterNoEscape('update.work_notes', current.work_notes);
s2.setStringParameterNoEscape('update.contact_type', current.contact_type);
s2.setStringParameterNoEscape('update.subcategory', current.subcategory);
s2.setStringParameterNoEscape('update.priority', current.priority);
s2.setStringParameterNoEscape('update.description', current.description);
s2.setStringParameterNoEscape('update.location', current.location);
s2.setStringParameterNoEscape('update.assignment_group', current.assignment_group);
s2.setStringParameterNoEscape('update.comments', current.comments);
s2.setStringParameterNoEscape('update.cmdb_ci', current.cmdb_ci);
s2.setStringParameterNoEscape('update.closed_at', current.closed_at);
s2.setStringParameterNoEscape('update.opened_by', current.opened_by);
s2.setStringParameterNoEscape('update.correlation_id', current.sys_id);
// Attachments handling code
var attachments = new GlideSysAttachment();
var attachmentGR = new GlideRecord('sys_attachment');
attachmentGR.addQuery('table_name', 'incident');
attachmentGR.addQuery('table_sys_id', current.sys_id);
attachmentGR.query();
while (attachmentGR.next()) {
var fileContents = attachments.getBytes(attachmentGR); // Get attachment contents
var base64EncodedFile = GlideStringUtil.base64Encode(fileContents); // Encode contents to base64
// Now, you can use base64EncodedFile to attach the file to the SOAP message
// Add your code here to attach the file to the SOAP message
// For example, you may need to set a parameter in your SOAP message with the base64EncodedFile value.
}
var response2 = s2.execute();
var responseBody2 = response2.getBody();
var status2 = response2.getStatusCode();
} else {
// Handle the case where the incident doesn't exist in the other system
// ...
}
})(current, previous);
Please, don't forget to mark my answer as correct if it solves your issue or mark it as helpful if it is relevant for you!
Regards,
Tushar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2023 05:32 AM
Hi,
its not working
i have changed this code its not saving the data in eccqueue table nd attchaments table based on that what should i write the code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2023 05:50 AM
is lemongrass an external app with which you are integrating?
Did you check how it expects the attachment data?
What debugging have you done so far?
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-29-2023 06:00 AM
we have created the name of soap message is lemon grass its is not external app. We are trying to attachement from one instance to another instance.