Upload file to Fibery in Action button

Is it possible to use markdown (e.g. while generating a PDF) to get the contents of rich text fields?
Or do I have to resort to JS? :frowning:

Hi, @Chr1sG

There is just text area for editing templates now. But we are going to add more powerful editor for markdown in future for PDF or Document templates in future.

Thanks,
Oleg

1 Like

@Chr1sG

In case if it was a question about how to retrieve document using script

const fibery = context.getService('fibery');
const markdownContent = await fibery.getDocumentContent(`secret`, `md`);

Thanks,
Oleg

Hi, @Sylvain_Vuilliot

Please find the example on how add file to entity from URL below

const fibery = context.getService('fibery');

for (const entity of args.currentEntities) {
    await fibery.addFileFromUrl(`https://fibery-public-assets.s3.amazonaws.com/apps/integrations/gitlab.png`, `gitlab.png`, entity.type, entity.id, null);
}

There are 5 arguments

  1. HTTP(s) url
  2. File name
  3. Entity type
  4. Entity id
  5. Authentication headers which should be provided if url is not public and secured. Provide null or {} if auth is not needed

Thanks,
Oleg

1 Like

I just meant that, at the moment, the guide for how to create markdown templates seems to only demonstrate how to refer to simple text fields.
I was wondering how to use markdown to refer to rich text (or other field types for that matter).

1 Like

Got it. So it makes sense to proceed in the following way.

  1. Retrieve document secret of the rich field or linked document
  2. Retrieve MD content
<%
const fibery = context.getService('fibery');
const markdownContent = await fibery.getDocumentContent(`secret`, `md`);
%>
  1. Paste into the corresponding place of the template <%= markdownContent.content %>

Thanks,
Oleg

1 Like

Thanks.
Can you give a template for retrieving the secret please, I’m not sure I fully understand the api documentation.

Here we go

<%
const fibery = context.getService('fibery'); 
const entity = await fibery.getEntityById(Entity.Type, Entity.Id, ['Description']);
%>
There is a document secret: <%= entity["Description"].secret %>
2 Likes

Thanks for that Oleg.
I’ve succeeded in generating a PDF containing the rich text field contents, but I did notice that where I have references to entities in the rich text field, they are replaced by [???] in the output.
I’m guess that there’s no easy fix for this :-/

Please attach example of your template and describe related fibery types schema. Will try to help you with that.

So this is the code I have used within the action button “Attach PDF using template”

<%
    const fibery = context.getService('fibery');
    const x = await fibery.getEntityById(Entity.Type, Entity.Id, ['Name','Description']);
    const markdownContent = await fibery.getDocumentContent(x["Description"].secret, `md`);
    const text = x.Name
%>
<% NAME(text) %>

{{Name}}

{{State.Name}}

**Description**

<%= markdownContent %>

The resultant PDF is named correctly, and contains what I would expect it to, except that any #mention of an entity in the description field shows as [???].

Please give me some time. Will get back to you tomorrow.

Hi, @Chr1sG

Sorry, unfortunately can not be done in a simple way right now. References indeed are returned as [???] from server. The workaround is pretty hard to implement and involves travelling in JSON of document. We will think about fixing the issue. Will let you know.

Thanks,
Oleg

1 Like

Thanks for getting back to me.
FYI my use case is to be able to create a record of an entity at a particular point in time (e.g. after approval/design freeze).
If the ability to generate PDF from an entity was natively implemented (as discussed here: PDF export of documents - #4 by anayericov) then the support for entity references in markdown would become less important.

1 Like

Actually you can open Entity as View and hit Print in browser. Most contemporary browsers support print into PDF. In that case Entity Mentions will be printed int PDF with their Names.

Hope this helps

Thanks @Viktar_Zhuk
I didn’t make it clear in my post that I was looking for an automated solution, e.g. when state = done, generate a pdf. Unfortunately, I can’t rely on the user to always remember to do it :-/

Thank you a lot.

It works well.
Only the filename argument does not seem to be respected : I get the file in fibery with name “File 16 Jun 2021 08_40_01.pdf” instead of “2021-06-16-F21030004.pdf”

I created a pull request in gitlab with the script
Script for generating pdf file via pdfMonkey and uploading it in fibery (!3) · Merge requests · fibery-community / Action Buttons · GitLab

Hope it will be helpful to others.

Hi, Sylvain

Thanks. Will check the issue with a file name.

Thanks,
Oleg

@Sylvain_Vuilliot The issue with filename is seems to be fixed and your request is merged.
Thanks for helping.

yes, perfect, thank you for the fix