Page 1 of 1

Download user record file in custom operation

Posted: Thu Jan 28, 2021 5:23 am
by CreditCircuit
We are trying to access a user's record of type file and provide a download link through a custom operation for user to download the stored file.

We have tried the following script copied from an example script in the Cyclos documentation but can't get it wo work; we'd appreciate some guidance please:

def recordTypeName = 'Invoices'
def invoiceNumberFieldInternalName = 'Invoice_Number'

// Fetch the invoice record with this invoice number
QRecordCustomFieldValue fv = QRecordCustomFieldValue.recordCustomFieldValue
UserRecord record = entityManagerHandler.from(fv)
.select(fv.owner())
.where(
fv.owner().type().internalName.eq(recordTypeName),
fv.field().internalName.eq(invoiceNumberFieldInternalName),
fv.stringValue.eq(invoiceNum))
.fetchFirst()

if (record == null) {

throw new ValidationException("The record with identifier $invoiceNumber doesn't exist")

}

def invoice = scriptHelper.wrap(record)

return [
content: invoice.Invoice_AOD_File[0],
contentType: "application/pdf",
name: invoice.Invoice_AOD_File[0].getName(),
length: invoice.Invoice_AOD_File[0].getLength(),
lastModified: invoice.Invoice_AOD_File[0].getLastModified()
]