Advertisement
Guest User

Untitled

a guest
Oct 16th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. //Convert attachment to base 64 string
  2.  
  3. var gsa = GlideSysAttachmentInputStream('e1d8bd45dbb103006cc25990cf96197b');
  4. var baos = new Packages.java.io.ByteArrayOutputStream();
  5. gsa.writeTo(baos);
  6. var base64Data = GlideStringUtil.base64Encode(baos.toByteArray());
  7.  
  8. //Convert the string to array chunks with 3736 chars length
  9. function splitString (string, size) {
  10. var re = new RegExp('.{1,' + size + '}', 'g');
  11. return base64Data.match(re);
  12. }
  13. var myarr = splitString(base64Data,3736);
  14.  
  15. //Send the array as Json via Rest
  16. var request = new sn_ws.RESTMessageV2();
  17. request.setEndpoint('https://dev24007.service-now.com/api/164669/valerianche');
  18. request.setHttpMethod('POST');
  19.  
  20. //Eg. UserName="admin", Password="admin" for this code sample.
  21. var user = 'admin';
  22. var password = 'Prohor@73';
  23. request.setBasicAuth(user,password);
  24.  
  25. //request.setRequestHeader("Accept","application/json");
  26.  
  27. var obj = {};
  28. obj.payload = myarr;
  29. var attachment = {
  30. table_name: 'incident',
  31. table_sys_id: '46ee851edb3103001c917befbf96195c',
  32. file_size: '3636',
  33. table: 'incident',
  34. file_name: 'KOP'
  35. };
  36. obj.attachment = attachment;
  37.  
  38.  
  39. request.setRequestBody(JSON.stringify(obj));
  40. //gs.log(request.getRequestBody());
  41. request.execute();
  42. var response = request.execute();
  43. gs.log(response.getBody());
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement