Skip to main content

Button Download Action

  1. Navigate to HSYCO Manager

  2. Create a new project or open an existing one

  1. Go to the Home page

  1. Click "add"

  1. Add a "Button"

  1. Go back to "edit" mode

  1. Align the button by clicking "Align" and then "Center Vertically" and "Center Horizontally"

8. Give the button an ID ("downloadbutton" for example). This is important because this will be the name of the command that this button will launch when pressed

  1. Change the "Label" to "Download"

  1. Change the "Description" to "Click to download from /test"

11. Change the "Action" to "download". As you can see, the "Name" attribute of the command is already set to the ID of the button

  1. Click "Save" to save the project

Tip: Great! Now we will write some code. When pressed, this button launched a command with the ID as the name. We need to capture that and return the full path to the file we want to download

  1. Go to the "File Manager"

  1. Navigate into the events folder

  1. Click "New File"

  1. Give it a name ("download.txt" for example) and click "New File"

**17. Copy the following code and save the file:

function userCommand(session, userid, name, param) : {
if(name.equals("downloadbutton")){
return "test/example.txt";
}
}

What this does is it captures the command with the name "downloadbutton", which is the ID of our button and also the name of the command, and it returns the path to the example.txt file in the /test folder uploaded in the "Button Upload Action" tutorial**

Tip: Good! Now we can try the button

  1. Re-open the project, click "Run" and then "Default" to launch the application

  1. The page should look like this:

  1. Click the Download button

Tip: The file should download to your local storage!