Skip to main content
July 24, 2024
Question

How should I first generate, then download the document by clicking the link that starts this process?

  • July 24, 2024
  • 4 replies
  • 0 views

Hello, I have the following code that calls an integration and it returns a file which saves in the file local variable.

I must be able to click the same link then generate and download the file stored in local!file

integration:

a!localVariables(
  local!file,
  a!richTextDisplayField(
    value: a!richTextItem(
      text: "Download Document",
      link: a!dynamicLink(
        saveInto: {
          rule!ADC_Gerar_Relatorio_Campanha(
            idCampanha: "2C918D8783461A630184BEC5E4453392",
            onSuccess: { a!save(local!file, fv!result.body),
            
             
            },
            onError: {}
          )
        }
      )
    )
  )
)

What solution would you recommend me? I have tried through an WebAPI as well:

a!localVariables(
  local!relatorioCampanha,
  local!docId: rule!ADC_Gerar_Relatorio_Campanha(
    idCampanha: http!request.queryParameters.cid,
    onSuccess: {
      a!save(local!relatorioCampanha, fv!result),
    },
    onError: {}
  ),
  a!httpResponse(
    headers: a!httpHeader(
      name: "Content-Disposition",
      value: concat("attachment")
    ),
    /*body: local!document,*/
    body: local!relatorioCampanha.body
    
  )
)

the I call the webAPI above through a safe link, but it is not working properly.

Thanks in advance

4 replies

July 24, 2024

This is my integration response

this is where i get its response, and expect to download as well

mikes0011
Brainy
July 24, 2024

Generally this is only easily accomplished via a 2-click approach - the first click fires off integration call which saves the generated doc ID into a local variable, and then your interface provides a download link (via a!documentDownloadLink()) after the ID is populated.

July 24, 2024

what if I want to generate the document when the page loads and then use the click to only download it?

mikes0011
Brainy
July 24, 2024

Assuming the user doesn't need to provide any input first that the document generation would depend on, then this should be possible by setting the value of the local variable holding the document ID to the integration that runs its generation process and returns the generated doc ID.