ERROR #5034: Invalid status code structure - Writing to File
I wrote a function awhile back to take Encoded Base 64 and write the PDF out to a file that could be sent to a faxing system to fax out. We are trying to test this code out in IRIS and I am seeing an error that I have not seen before... ERROR #5034: Invalid status code structure
Here is the code...
ClassMethod DecodeBase64HL7ToFile(base64 As %Stream.GlobalBinary, Ancillary As %String, FileName As %String) As %String
{
set ArchDir = "/ensemble/data/transfer/AncillaryPDF/"
set ArchAncDir = ArchDir_Ancillary_"/"
set FaxDateDir = ArchAncDir_$PIECE($ZDATE($HOROLOG,7)," ",1)_"-"_$PIECE($ZDATE($HOROLOG,7)," ",2)_"-1/"
if '##class(%Library.File).DirectoryExists(ArchDir)
{
do ##class(%Library.File).CreateDirectory(ArchDir)
}
if '##class(%Library.File).DirectoryExists(ArchAncDir)
{
do ##class(%Library.File).CreateDirectory(ArchAncDir)
}
if '##class(%Library.File).DirectoryExists(FaxDateDir)
{
do ##class(%Library.File).CreateDirectory(FaxDateDir)
}
set Oref = ##class(%FileBinaryStream).%New()
///$$$LOGINFO(FaxDateDir_FileName)
set Oref.Filename = FaxDateDir_FileName
Do base64.Rewind()
While 'base64.AtEnd {
set ln = base64.ReadLine()
set lnDecoded = $system.Encryption.Base64Decode(ln)
do Oref.Write(lnDecoded)
}
Do Oref.%Save()
set PDFFilePath = FaxDateDir_FileName
return PDFFilePath
}
Why is IRIS throwing an error? I want the Path returned to the DTL that it is being called from. Can I no longer return a string?
Hi Scott,
Am wondering whether this is due to migrating from AIX to RedHat, and the stream is defaulting to expecting a different line terminator $C(13,10).
Could try add before the while loop:
set ln=base64.ReadLine() set:ln[$C(10) base64.LineTerminator=$C(10) do base64.Rewind()
Kind regards,
Alex
Alex,
I tried that but now I am receiveing... ERROR #5002: ObjectScript error: <UNDEFINED>zDecodeBase64HL7ToFile+22^osuwmc.Functions.1 *%C(10)
ClassMethod DecodeBase64HL7ToFile(base64 As %Stream.GlobalBinary, Ancillary As %String, FileName As %String) As %String
{
set ArchDir = "/ensemble/data/transfer/AncillaryPDF/"
set ArchAncDir = ArchDir_Ancillary_"/"
set FaxDateDir = ArchAncDir_$PIECE($ZDATE($HOROLOG,7)," ",1)_"-"_$PIECE($ZDATE($HOROLOG,7)," ",2)_"-1/"
if '##class(%Library.File).DirectoryExists(ArchDir)
{
do ##class(%Library.File).CreateDirectory(ArchDir)
}
if '##class(%Library.File).DirectoryExists(ArchAncDir)
{
do ##class(%Library.File).CreateDirectory(ArchAncDir)
}
if '##class(%Library.File).DirectoryExists(FaxDateDir)
{
do ##class(%Library.File).CreateDirectory(FaxDateDir)
}
set Oref = ##class(%FileBinaryStream).%New()
///$$$LOGINFO(FaxDateDir_FileName)
set Oref.Filename = FaxDateDir_FileName
Do base64.Rewind()
While 'base64.AtEnd {
set ln = base64.ReadLine()
set:ln[%C(10) base64.LineTerminator=$C(10)
set lnDecoded = $system.Encryption.Base64Decode(ln)
do Oref.Write(lnDecoded)
}
Do Oref.%Save()
set PDFFilePath = FaxDateDir_FileName
return PDFFilePath
}
Excuse the typo: Should be "$C(10)" not "%C(10)"
set:ln[$C(10) base64.LineTerminator=$C(10)
we need to handle 2 types of line terminators. $C(13,10) and $C(10)
+ BASE64 holds only printable characters, $C(13) is a NONO in Base64.
So:
if you always use $c(10) as line terminator
then set ln=$TRANSLATE(ln,$c(13)) will remove also a leftover $C(13) if existing
or just do nothing.
I didn't realize I had posted this same error years ago. The answer was in my other post. In the DTL I was setting the Path = tSC which was being used in other ways.
EDIT: Hah, I guess you posted your solution as I was typing this ... and yeah, sort of what I thought it might be
Are you calling (and testing) this from a DTL? If yes, have you looked through the DTL rules to see if the returned string's variable is being used as an argument to something like $system.Status.GetErrorText()?
Does the same thing happen when you execute it from the IRIS prompt?
Set tStrm=##class(%Stream.GlobalBinary).%New() Do tStrm.Write("SGVsbG8gV29ybGQh") Do tStrm.Rewind() Write ##class(<packagename>).DecodeBase64HL7ToFile(tStrm,"<ancillary>","</path/to/outputfile.ext>")
Replace <packagename>, <ancillary>, and </path/to/outputfile.ext> with values appropriate for what you're testing, of course ...
I did not get the same error, and it was successful.