- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-09-2014 02:11 AM
Hi
I'm using the below code in Incident business rule in Dev ServiceNow to insert an incident in my Test ServiceNow using SOAP Message. It is working fine.
But I also want to send over the attachments using the SOAPMessage. Is it possible to send attachments using SOAPMessage or do I need to define a seperate soapEnvelope and then use createElement?
var s = new SOAPMessage('Test-Incident', 'insert');
s.setStringParameter('u_vendor_reference', current.u_vendor_reference);
s.setStringParameter('caller_id', current.caller_id);
s.setStringParameter('location', current.location);
s.setStringParameter('u_contact_number', current.u_contact_number);
s.setStringParameter('description', current.description);
s.setStringParameter('cmdb_ci', current.cmdb_ci);
s.setStringParameter('u_source', current.u_source);
s.setStringParameter('u_raised_by', current.u_raised_by);
s.setStringParameter('assignment_group', current.assignment_group);
s.setStringParameter('assigned_to', current.assigned_to);
s.setStringParameter('state', current.state);
s.setStringParameter('priority', current.priority);
s.setStringParameter('category', current.category);
s.setStringParameter('u_subcategory', current.u_subcategory);
s.setStringParameter('short_description', current.short_description);
s.setStringParameter('description', current.description);
var response = s.post();
Thank you
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-12-2014 01:01 AM
Thanks to Kalai and Subajit.
Based on your responses I created a SOAP Message for target instance and used the below script to check the response first and then send the attachments.
var s = new SOAPMessage('Test-Incident', 'insert');
s.setStringParameter('u_vendor_reference', current.u_vendor_reference);
s.setStringParameter('caller_id', current.caller_id);
s.setStringParameter('location', current.location);
s.setStringParameter('u_contact_number', current.u_contact_number);
s.setStringParameter('description', current.description);
s.setStringParameter('cmdb_ci', current.cmdb_ci);
s.setStringParameter('u_source', current.u_source);
s.setStringParameter('u_raised_by', current.u_raised_by);
s.setStringParameter('assignment_group', current.assignment_group);
s.setStringParameter('assigned_to', current.assigned_to);
s.setStringParameter('state', current.state);
s.setStringParameter('priority', current.priority);
s.setStringParameter('category', current.category);
s.setStringParameter('u_subcategory', current.u_subcategory);
s.setStringParameter('short_description', current.short_description);
s.setStringParameter('description', current.description);
var response = s.post();
gs.addInfoMessage(response.toString());
var helper = new XMLHelper(response);
var obj = helper.toObject();
logObj(obj, "*" );
function logObj(obj, sep){
for (x in obj){
if (typeof obj[x] != "function"){
if(x == "sys_id" && JSUtil.notNil(obj[x])){
gs.log(sep + x + ":: " + obj[x]);
//Attachment Creator
var grSysAtt = new GlideRecord('sys_attachment');
grSysAtt.addQuery('table_sys_id', current.sys_id);
grSysAtt.query();
while (grSysAtt.next()){
gs.log(grSysAtt.table_sys_id + 'sys id of the record foound');
var sa = GlideSysAttachment();
var binData = sa.getBytes(grSysAtt);
var encData = GlideStringUtil.base64Encode(binData);
gs.log("Encoded data:" + encData);
var sm = new SOAPMessage('Test-Attachments', 'insert');
sm.setStringParameter('agent', 'AttachmentCreator');
sm.setStringParameter('topic', 'AttachmentCreator');
sm.setStringParameter('payload', encData);
sm.setStringParameter('name', grSysAtt.file_name+':'+grSysAtt.content_type);
sm.setStringParameter('source', grSysAtt.table_name+':'+obj[x]);
var response2 = sm.post();
}
}
}
logObj(obj[x], sep + "*" );
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2016 09:52 AM
Hi Kris,
I tried your approach to no avail. Is this functionality still working for you or have you had to make changes post new release?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-07-2016 10:21 AM
Hi Abdul,
It may not be specifically relevant to your requirements but it maybe worth noting that there a cute REST attachment api available in Geneva
which is not subject to a Max of 5MB
AttachmentCreator SOAP Web Service - ServiceNow Wiki
..
6 FAQ
- How many attachments can you send in one message
- Only one attachment per message
- Is there size limit on the attachment in the message
- Attachments are limited to a maximum of 5MB.
Best Regards
Tony
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-24-2016 02:23 PM
Thanks Tony, I have now implement this functionality.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-10-2016 04:31 AM
this might help to understand the approach of sending files via Web Service ServiceNow Attachment Files via Web Service - YouTube