DEV Community

Derrick Sherrill for WayScript

Posted on

Programmatically Create and Share Files using WayScript

Introduction

Providing information to your team quickly is a staple of an efficient business. However, the coordination of these files is often very inefficient. Without automation you or your team may have to prepare files to share with others. This can be things such as generating sales reports, safety incidents, HR documents, and much more. Whenever you find yourself creating the same files on a consistent basis, consider WayScript.

In this tutorial, I want to show you how easy it is to build a programmatic file generator, using your data, and then share this with others in your organization easily. Let's get started!

Prerequisites

No prerequisites, but some content you might find helpful:

How to Programmatically Generate Files

What do I mean when I say "programmatically" generate files? What I'm talking about is using programming logic to create your files for you. With many reports we already have the available data, we just need to do something with it. This is where wayscript really shines. With our dozens of integrations, we make it easy to connect your data storages and use their data within our editor.

These are just a few of the available ones and we're always adding more. I'll do this demo using data from a google sheets integration.

Creating a Way to Instantly Share Files

Sometimes rather than hosting a file online, we want our end user of the file to be able to instantly download it. With WayScript we can accomplish this by using an HTTP endpoint that we create with the HTTP Trigger. A trigger in wayscript is just a way for us to activate our script and do whatever actions it is that we created. This will work perfectly, as we can create the file whenever the user visits the url and then downoad it to their machine. This means that the end user will always have the most up to date data this way. We'll create the trigger above our google sheets module in our workflow:

By using this trigger, we also get a few customizations that we can apply to our new URL endpoint. These include advanced features such as password protecting your endpoint and requesting query parameters from the url.

The cool part about these advanced features, is we could generate custom reports depending on the query parameters the user passes. For example, within our script we could have different filtering actions of our google sheet module, depending on a "user" query parameter. Then, we could instruct our team to put their name as the parameter to receive their own custom report with only data useful to them. We won't do that in this tutorial, but we'll cover that in a separate one.

Creating the File

Now that we have the trigger and data storage in place, we'll need to do something with that data. We hope you will find robust solutions here to create exactly what you want. We have options for everyone. If you're technically minded, we full programming modules incorporated such as python, javascript, sql, and GraphQL. Not so technically minded? We have prebuilt code logic modules that should be able to accomplish what you want to do.

To keep it simple in this tutorial, we'll just use some prebuilt looping logic to iterate over values in a list, and create an excel file.

Returning the File to a User

Once we have created the file on our WayScript account, we just need to be able to share this file with another user. Like stated before, we'll use a link which downloads the file on the end user's computer. To set this up, we'll use the http trigger we specified earlier and an http response. This response can be used to return a 200 status code and also the download:

Questions?

Feel free to message us with any questions on Discord. We're happy to help! If you want to see this full script template, you can find it here

Top comments (0)