Download user record file in custom operation

Any issue about Cyclos 4 scripting and Webservices

Moderators: rmvanarkel, hugo, alexandre

Post Reply
CreditCircuit
Posts: 11
Joined: Wed May 09, 2018 4:45 pm

Download user record file in custom operation

Post 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()
]
Post Reply