10.23.2008 | |

BEA BPM Enterprise 6.0 - creating an excel and attaching it to the instance/ticket

this one was tricky! it took me several tries to finally figure out what was going on. first attempt i tried loading the excel com service. and i wrote some code to create the file (just search for excel examples on bea.com's website - they have several) and attach it (using the simple Attachment.create...). however here is the problem. just b/c it works on studio, doesn't mean it will work on enterprise. when using studio your com bridge is usually automatically started. on enterprise you have to go to the server that is running bpm and make sure the com bridge is a service that is automatically running and make sure that the port for the com bridge is open to use. (make sure no firewalls are blocking it). i was able to get that far and have the excel document be created, but for some reason it wouldn't close the file! i had close worksheets, close worksheet, and quit application in my code and it wouldn't work. it left the process running. so after several attempts, i decided to take a different direction. here's what i did to make it work:

i went about it a completly different way. i simple wrote a text file using Fuego.Io.textFile. here's an example:

stText as String
textFile as Fuego.Io.TextFile
excelFileName = "C:\\niki.csv"
excelFile = "niki.csv"
myFile as Fuego.Io.File
textFile = Fuego.Io.TextFile()
result2 as Bool

logMessage "entering create requestor text"
openForWriting(textFile, name : excelFileName, append : false, lineSeparator : "\n")
stText = "Niki's file"
result2 = writeLineTo(textFile, line : stText)
close textFile

simple, right? then i just needed to attach it. here's where i ran into problems. i couldn't figure out why it would show up as a csv file sometimes and then other times it would come up as document.htm. luckily i currently work with some smart people who pointed me in the right direction. document.htm means that the file size has grown so large it didn't read the whole file. so it would work if the file was less than 512 and if it was larger i would get the document.htm result. so i started researching mime types. after using google, if found a website that gave the different types of mime files to use with csv. after several attempts i figured out that application/csv was the one i needed to get my attachments to work correctly. here's the attachement info that worked:

if not excelFileName is null and excelFileName != "" then
binaryFileContents = BinaryFile.readToBinaryFrom(name : excelFileName)
Attachment.create(contents : binaryFileContents,
contentType : "application/csv", name : excelFile, description : "Closed Ticket Summary",
remarks : "Ticket is Closed")
end

note that the excelFileName is the path and filename. now when the user is in their inbox they can view an attachment and it will open in excel. it's a comma delimited file, so where ever you are needing the information in the file to show up in the next column - just put a comma - and magically it will be in the next column

0 comments: