Generate download link when clicking on button

Certified Senior Developer

Hi there,

I have created a button to generate CSV file but after clicking on button- page redirects to home page. 
I want to create document link when clicking on button so that file get downloaded. How can I do this in interface?

Thanks

  Discussion posts and replies are publicly visible

Parents
  • 0
    Certified Senior Developer

    Hello ,

    Does this button trigger a Start process? If so I would recommend you to use a Record/Related actions to perform this and try using a User Input task where the user has a summary of what kind of document and what data is there and so on, add a document download link using a!documentDownloadLink() pass your generated document as the value here. 

    I guess this would help and this is what you were asking for. If not please ignore.

  • 0
    Certified Senior Developer
    in reply to Konduru Chaitanya

    I am using rich text and startprocess link. Want to generate a file document link.

    1. pleeeeeeease use "insert code" for code of... any length
    2. you would need to add the "onSuccess" parameter within your a!startProcess call in order to call the generated document ID back into your interface (just store in a local variable, etc).
  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

    a!buttonArrayLayout(
    buttons: {
    a!buttonWidget_23r3(
    label: "Generate File",
    value: cons!IPA_VAL_DATA,
    saveInto: {
    ri!buttonValue,
    a!save(
    ri!assign.preparedby,
    local!loggedInUser
    ),
    a!startProcess(
    processModel: cons!IPA_DATA_PROCESS_MODEL,
    processParameters: {
    employee:ri!employee,
    address:ri!address,
    tax:ri!tax,
    assigne:ri!assigne
    buttonValue:ri!buttonValue
    },
    onSuccess: {
                          a!httpResponse(
                            statusCode: 200,
                            headers: {
                              a!httpHeader(
                                name: "Content-Type",
                                value: "application/json"
                              )
                            },
                            body: fv!processInfo
                          )
                        }
    )
    },
    
    submit: false(),
    validate: false(),
    style: "SECONDARY",
    
    )
    },
    align: "START",
    marginAbove: "STANDARD"
    ),

    Can you check?

  • 0
    Certified Lead Developer
    in reply to manjit.1486

    Why do you try to put a HTTP response into a button? That will not do anything.

    What Mike tried to explain, is that you need to store the ID of the generated document from the process into a local variable. Then show a link component to allow the user to download the file.

  • 0
    Certified Senior Developer
    in reply to Stefan Helzle

    a!buttonArrayLayout(
    buttons: {
    a!buttonWidget_23r3(
    label: "Generate File",
    value: cons!IPA_VAL_DATA,
    saveInto: {
    ri!buttonValue,
    a!save(
    ri!assign.preparedby,
    local!loggedInUser
    ),
    a!startProcess(
    processModel: cons!IPA_DATA_PROCESS_MODEL,
    processParameters: {
    employee:ri!employee,
    address:ri!address,
    tax:ri!tax,
    assigne:ri!assigne
    buttonValue:ri!buttonValue
    },
     onSuccess: {
                    a!save(local!docId,fv!processInfo),
                    )
                  },
                  onError: a!save(
                    local!errorMessage,
                    "Error Exporting File to Excel"
                  )
    )
    },
    
    submit: false(),
    validate: false(),
    style: "SECONDARY",
    
    )
    },
    align: "START",
    marginAbove: "STANDARD"
    ),

  • You need to read the details in the rule description for a!startProcess - granted it's not SUPER well explained at a surface level, but it's also not that hard.  The highlighted snippet is what you're missing in the above iteration:

  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

    Thanks for the information. I am following the above highlighted snippet. But when I used that local variable in documentdownload link. It gives an error.

    a!buttonArrayLayout(
    buttons: {
    a!buttonWidget_23r3(
    label: "Generate File",
    value: cons!IPA_VAL_DATA,
    saveInto: {
    ri!buttonValue,
    a!save(
    ri!assign.preparedby,
    local!loggedInUser
    ),
    a!startProcess(
    processModel: cons!IPA_DATA_PROCESS_MODEL,
    processParameters: {
    employee:ri!employee,
    address:ri!address,
    tax:ri!tax,
    assigne:ri!assigne
    buttonValue:ri!buttonValue
    },
     onSuccess: {
                    a!save(local!docId,fv!processInfo.pv.docId),
                    )
                  },
                  onError: a!save(
                    local!errorMessage,
                    "Error Exporting File to Excel"
                  )
    )
    },
    
    submit: false(),
    validate: false(),
    style: "SECONDARY",
    
    )
    },
    align: "START",
    marginAbove: "STANDARD"
    ),
      a!linkField(
                label: "Download document",
                labelPosition: "ABOVE",
                links: {
                  a!documentDownloadLink(
                    label: document(
                      documentId: local!docId,
                      property: "name"
                    ),
                    document: local!docId
                  )
                }
              )

    Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error at function 'document' [line 945]: The passed parameter(s) are of the wrong type. Received the type Text.

    What I am missing? I tried change the type - still gets an error. 
    pv.docId is integer type.

  • Make sure you account for the fact that the Doc ID will be blank at first.  It will be easier if you use a!richTextDisplayField() (i recommend nobody EVER use a!linkField() at this point, it is essentially deprecated by the existence of the Rich Text field) - the benefit here is you can either hide the field entirely and/or disable the link while the local variable containing the document ID is still blank.

  • 0
    Certified Senior Developer
    in reply to Mike Schmitt

    I got it. I used this a!richTextDisplayField(). But still why it's giving me an errror.
    Could not display interface. Please check definition and inputs. Interface Definition: Expression evaluation error at function 'document' [line 949]: Document Does Not Exist or has been Deleted

  • 0
    Certified Lead Developer
    in reply to manjit.1486

    You should display that link only if the document is not null.

  • 0
    Certified Senior Developer
    in reply to Stefan Helzle

    I really don't know what's happening.

          a!richTextDisplayField(
            value: a!richTextItem(
              text:"Dowload Document",
              link: a!documentDownloadLink(
                label: document(
                  documentId: if(rule!GLB_isBlank(local!docId),null(),local!docId),
                  property: "name"
                ),
                document: if(rule!GLB_isBlank(local!docId),null(),local!docId)
              ),
              showWhen: not(rule!GLB_isBlank(local!docId))
              )
            ),

Reply Children