Skip to main content


 

Symptoms


Regarding Getting Back Binary Data From SAP.
 

Diagnoses



We are getting a pdf from SAP to render it back on k2 forms.

K2 Connect / ERP Connect when it converts/ cast the datatype Xstring (Hex encoded String) from SAP, it automatically converts it to Binary. i.e Bytet] DataType in .Net.

Then there is a KB which Says We have to Transform the Data to 64Base encode by K2. I have transformed the Data as per the Article.

https://www.k2.com/onlinehelp/k2connect/userguide/4.6.5/webframe.html_Using_K2_Connect_Transformation_mapping_to_return_SAP_binary_data_to_SmartObjects.htm
l
I can see the Data in Smart Object Tester.

But the Data Fails when we convert back to binary or display it in browser on object tag , attached the pdf.txt (change the extension to html) with the 64base encoded data.

When I directly get the pdf from SAP and 64base encode it the data is different.

Why is the Data Converted to binary back and why cannot it be hex string in the test cockpit and smart object tester. so ther won't be any change in data. How is ERP connect Dealing with the conversion of HEX back to Binary Data.



 

Resolution

Logged Documentation to be updated . Fixed code supplied in the ticket notes

Pulling Binary Data from SAP , such as a PDF , and converting it to BASE64 so that K2 can understand it was not functioning , resulting in junk data coming back ... additionally making it impossible to encode it back to Binarya] again .

ERP Connect already provides the information in Bytey] so this is not needed

// System.IO.MemoryStream ws = new System.IO.MemoryStream()
//System.Runtime.Serialization.Formatters.Binary.BinaryFormatter sf = new System.Runtime.Serialization.Formatters.Binary.BinaryFormatter()
// sf.Serialize(ws, PDF_DOC)

And find below the modified Transform Method . Added error handling and removed the unnecessary Binary Formatting and Serialization


private void Transform (System.Bytey] PDF_DOC, ref System.String File)
{
File=String.Empty
try
{
if (PDF_DOC.Length > 0)
{
long length = 0
length = PDF_DOC.Length
string encodedData = Convert.ToBase64String(PDF_DOC, Base64FormattingOptions.None)
File = encodedData
}
}
catch (Exception ex)
{
File = ex.StackTrace
}
}




 
Be the first to reply!

Reply