Custom print report - JS engine

Hi, i can’t seem to find a way to use Custom Print Report as a function for post-JS engine.

I would like to have an action, where custom print report PDF file would be generated for entry and then attached to a file upload field in that same entry.

Maybe somebody could offer some workaround?

  • First, generate a custom print report (Custom Print Report).
  • After downloading it, locate the original URL of the file. Copy the entire portion starting from “.carbone?” to the end.
  • In the workflow, use util.downloadFile to fetch the specific data. For example:
    https://ap11.ragic.com/demo/test/2/0
    Then append the part you just copied to the URL, like this:
    https://ap11.ragic.com/demo/test/2/0.carbone?fileFormat=pdf&fileNameRefDomainId=-1&customPrintTemplateId=1&converter=L
    This will download the PDF into the database and return the file name.
  • Then, use setFieldValue to fill the file upload field with the returned file name.

Here is a general example:

var fileName = util.downloadFile(yourURL);
var query = db.getAPIQuery(pathToForm);
var entry = query.getAPIEntry(id);

entry.setFieldValue(fieldId, fileName);
entry.save();

Thank you dearly, i called the function and file was saved successfuly, however file is saved only with default file name and not the one provided for Carbone engine (i have specific field for file name and it is set in Advanced options). If i download report - i get a nice file name from field, if i use function to save file with your provided method - i get default file name. I tried to do a custom function to rename the file:

            var documentName = entry.getFieldValue(1000376);

            var newFileName = documentName + ".pdf";

            entry.setFieldValue(1000544, newFileName);

But for some reason file is empty after renaming it.

When I tested on my end, adding fileNameRefDomainId=fieldId to the download parameters successfully saved the file to the database using the field value as the filename.
Could you please provide me with the string after .carbone? in your download URL for reference?

Hi!

After adding fileNameRefDomainId=fieldId it also worked for me!!! Thank you!

One last thing to go is finding a way to add Latin Extended letters to file name. I tried
decodeURIComponent(pdfUrl) but it doesn’t work. If i decode before saving file - file name is not decoded, instead of letters ąčęėįšųūž i see “%25C4%2585%25C4%258D%25C4%2599%25C4%2597%25C4%25AF%25C5%25A1%25C5%25B3%25C5%25AB%25C5%25BE” in file name. If i decode AFTER downloading file - file name is decoded as intended, but file itself is broken. Any ideas on this? And thank you for your kind help. A LOT.