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 Reply Children
  • 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"
    ),

  • 0
    Certified Lead Developer
    in reply to manjit.1486

    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.

  • 0
    Certified Lead Developer
    in reply to manjit.1486

    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))
              )
            ),

  • 0
    Certified Lead Developer
    in reply to manjit.1486

    That depends on what this GLB_isBlank is doing. Why not use a!isNotNullOrEmpty()?

  • 0
    Certified Senior Developer
    in reply to Stefan Helzle

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

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

  • 0
    Certified Lead Developer
    in reply to manjit.1486

    You need to check the value of local!docId.

    This should not be much of a challenge for a senior developer !?!?!?