Working with files in Groove seems to be a theme, this month. We're just finishing off a project for a customer who has lots of forms records with lots of attachments. This is affecting forms performance, as well as being unwieldy, so we're moving the attachments out of the forms tool and info a files tool. This makes them amenable to searching with our recent free Tocuan FileFinder application.
Here's the script that extracts the files from the forms tool, written in the Boo programming language:
/*
Class: ExportAttachments
Exports the attachments from a forms tool
*/
class ExportAttachments (GrooveScript):
def Main():
try:
space = Groove.GetSpace("DMS2")
formsTool = space.GetFormsTool("Billing")
data = formsTool.GetData("All Records", "", true)
table = data.Tables[0]
for row in table.Rows:
cust = row["CustomerName"]
purchaseOrder = row["PONum"]
rec = GetFormsRecord(row)
print "${cust}/${purchaseOrder}"
for attachment in rec.Attachments:
attachment.SaveToFolder("C:\\temp\\${space.Name}\\${cust}\\${purchaseOrder}");
except e:
ReportError(e)
I'm pretty happy with this - it expresses my needs clearly with (almost) a minimum of overheads. I particularly like the the SaveToFolder call which constructs the folder path using the variables declared earlier on. The only ugliness is getting the data with GetData, and then getting the zeroth table from Groove in two lines rather than one.
What about error checking you may ask? Well, it is included - at two levels. First, if there was any of the usual problems (space or tool not existing for example), you would see a warning message. GetSpace, for example, will post a warning message if the space does not exist. If something unusual happens, the ReportError script function will give you a detailed report.
Of course, I'm only going to take a part of the credit - the code responsible for integrating with Groove. The clarity of programming in Boo is down to Rodrigo B. de Oliveira and numerous supporting developers.
If you want to have a play with Bambuco - go right ahead and download it here.
No comments:
Post a Comment