-1

I am trying to upload a file into ServiceNow using the WSDL <https://instanceName.Service-now.com/ecc_queue.do?WSDL>

I am converting the file to Base64 using Powershell. The upload via SOAPUI works fine, however the same file when downloaded is corrupted. If I upload an Excel file with data on downloading the file the Excel file is Empty

Source File Name is tp-certification-guide.pdf (Source PDF: - https://www.servicenow.com/content/dam/servicenow/other-documents/training/tp-certification-guide.pdf)

However, when I convert the file to Base64 using a portal (https://www.browserling.com/tools/file-to-base64/), I am able to upload and download the file without any issues. Again the file uploaded to ServiceNow does not get corrupted nor does it download an Empty File.

My SoapUI code: -

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ecc="http://www.service-now.com/ecc_queue">
<soapenv:Header/>
  <soapenv:Body>
    <ecc:insert>
      <agent>AttachmentUploader</agent>
      <name>problem_data.pdf:application/pdf</name>
      <payload>AAAAIGZ0eXBxdCrG[..truncated..]</payload>;
      <source>incident:[sysid is here]</source>
      <topic>AttachmentUploader</topic>
    </ecc:insert>
  </soapenv:Body>
</soapenv:Envelope>
Above Code taken from https://www.servicenowguru.com/integration/sending-attachment-servicenow/

My PowerShell code is as below

$InputFile = "D:\02_Downloads\ChromeDLs\tp-certification-guide.pdf"

# Read the file as text
$Text = [System.IO.File]::ReadAllText($InputFile)

# Convert the string to UTF-8 bytes
$UTF8Bytes = [System.Text.Encoding]::UTF8.GetBytes($Text)

# Encode the UTF-8 bytes as a Base64 string
$Base64String = [System.Convert]::ToBase64String($UTF8Bytes)

$Base64String | Out-File "D:\02_Downloads\ChromeDLs\tp-certification-guide.txt"

The file should uploaded to ServiceNow using the WSDL and the same file when downloaded should not be corrupted or empty.

I feel there is something wrong in the generation of Base64 using Powershell compared to the Online Edition which would need assistance.

esqew
  • 42,425
  • 27
  • 92
  • 132
NottyHead
  • 181
  • 4
  • 18
  • Why aren't you converting the file to a Base64 representation within Blue Prism? Seems a bit tedious and unnecessary to farm this out to PowerShell, no? – esqew Sep 10 '19 at 12:47
  • In any case, please show us what you've tried so far - you've provided no insight into what your current Blue Prism code is and why that piece isn't working. – esqew Sep 10 '19 at 12:48
  • I don't think this can be done within Blue Prism – NottyHead Sep 10 '19 at 15:16
  • How did you reach the conclusion that a file can't be Base64 encoded within Blue Prism? I would disagree wholeheartedly, as I've built Business Objects to perform this function exactly. – esqew Sep 10 '19 at 15:17
  • I am wrong in saying that it can't be done in BluePrism, but when you are in pressure cooker situation, The Visual basic codestage is so primitive that I would prefer using PowerShell. If you could help me there it would be great... Or even direct me on links to build a VBO, I can try that too. – NottyHead Sep 13 '19 at 00:45

1 Answers1

1

I can't help you with the base64 problem, but if you're interested, then here's my dotnet code to upload attachment to SNOW using REST.

Dim request As WebRequest = WebRequest.Create(REST_Address)
request.UseDefaultCredentials = True
request.Credentials = new NetworkCredential(SNOW_Username, SNOW_Password)
request.Method = "POST"
request.ContentType = ContentType


Dim byteArray As Byte() = System.IO.File.ReadAllBytes(Filename)

request.ContentLength = byteArray.Length
Dim RequestStream As System.IO.Stream = request.GetRequestStream()
RequestStream.Write(byteArray, 0, byteArray.Length)
RequestStream.close()

Dim response As WebResponse = request.GetResponse
Dim responseStream As IO.Stream = response.GetResponseStream
Dim sr As New IO.StreamReader(responseStream)

resultData = sr.ReadToEnd
response.Close

Inputs

REST address example: https://instance.service-now.com/api/now/attachment/file?table_name=SNOWTable&table_sys_id=32charsysid&file_name=test.pdf

content type: application/pdf

Andrzej Kaczor
  • 1,553
  • 1
  • 11
  • 18