Dittofi
  • Tutorials
    • Tutorial Index
    • Quick Start
    • Dittofi Essentials
      • Part 1: Frontend terms and concepts
      • Part 2: Backend terms and concepts
      • Part 3: Connecting frontend and backend
      • Part 4: Dittofi app structure
    • Dittofi App Design
      • 🏗️App architecture 101
      • ◼️Backend app development 101
      • 🟪Frontend app development 101
      • 🔰(optional) Web developer beginner series
  • Learn Frontend
    • 👨‍💻Getting Started
      • Welcome to Dittofi
      • Intro to the Dittofi Design Studio (Frontend)
    • 🟩Pages
    • 🟪Elements
      • Types
        • Button Element
        • Div Block Element
        • Form Block Element
        • Link Block Element
        • List Element
        • Modal Box Element
        • Tabs Element
        • Columns Element
        • Image Element
      • Partials
      • Prefabs
      • Custom
    • 🟧Variables
      • Array
      • Checkbox
      • Collection
      • Collection (Custom Model)
      • Collection (System Custom Model)
      • Custom Model
      • Date
      • Datetime
      • File
      • Json
      • Number
      • Number with decimal
      • Model
      • System Custom Model
      • Text
      • UUID
    • 🟨Events
      • 🟨External
        • HTTP Request
        • Run Endpoint
      • 🟨Flow Control
        • Condition
        • Run Action
        • Loop
        • Sleep
      • 🟨Maths
        • Add
        • Divide
        • Modulus
        • Multiply
        • Subtract
      • 🟨Navigation
        • Open Page
      • 🟨Notifications
        • Alert
        • Confirm
      • 🟨Other
        • Copy To Clipboard
        • Run Custom
      • 🟨Text
        • Concat
        • Contains
        • Ends With
        • I Contains
        • I Ends With
        • I Starts With
        • LTrim
        • RTrim
        • Text To Upper
        • Text To Lower
        • Trim
        • Starts With
      • 🟨Variables
        • Set Field
        • Remove Field
      • Validate
    • 🟦CSS Layouts
      • Holy Grail Layout
      • Side Bar Layout
      • Sticky Footer Layout
      • Sticky Header Layout
      • CSS Frameworks
    • 🔲CSS Frameworks
    • Component Libraries
    • Meta Attributes
  • Learn Backend
    • 🖥️Getting Started
      • Intro to Data
      • Intro to APIs
      • Build your first custom API
      • Actions & Events
    • 🟫Back-End Actions
    • 🟩Custom Models
      • 🟩Attributes
        • Array
        • Checkbox
        • Custom Model
        • Collection (Custom Model)
        • Collection (System Custom Model)
        • Date
        • Datetime
        • File
        • Number
        • Number With Decimal
        • Json
        • Text
    • ◼️Data Models
      • Database Fundamentals
        • Database relationships
      • ◼️Columns
        • Attachment
        • Auto Increment
        • Checkbox
        • Date
        • Datetime
        • Duration
        • Email
        • Long text
        • Link to another record field
        • Number
        • Number with decimal
        • Password
        • Phone number
        • Percent
        • Price
        • Rating
        • Single select
        • Single line text
        • URL
    • 🟥Events
      • 🟦Arrays
        • Append
        • Array Pop
        • At
        • Length
        • Prepend
        • Range
      • 🟦Conversions
        • Base64 Encode
        • Base64 Decode
        • Json Decode
        • Json Encode
        • Path Escape
        • Path Unescape
        • Query Escape
        • Query String Parse
        • Query Unescape
        • To Bool
        • To Float
        • To Int
        • To Str
        • Yaml Encode
        • Yaml Decode
      • 🟦Database Requests
        • Create
        • Create Or Update
        • Delete
        • Has Record
        • Read Event
        • Update
      • 🟦External
        • HTTP Request
        • SFTP Download
        • SFTP Upload
      • 🟦Files
        • CSV Reader Event
        • CSV Writer Event
        • File Read
        • File Save
        • File Size
        • File Type
        • JSON Reader
        • PDF Generator
      • 🟦Flow Control
        • Condition
        • Loop
        • Return
        • Run Action
        • Sleep
      • 🟦Notifications
        • Send Mail
        • Connect Websocket
        • Message Websocket
      • 🟦Maths
        • Add
        • Acos
        • Acosh
        • Asin
        • Asinh
        • Atan
        • Atanh
        • Cbrt
        • Ceil
        • Divide
        • Modulus
        • Multiply
        • Subtract
      • 🟦Security
        • Compare Password
        • JWT Decode
        • JWT Encode
        • Login
        • Logout Web User
        • Password Generator
        • Random Number
      • 🟦Time
        • Add Time
        • Day
        • Format Time
        • Minute
        • Nanosecond
        • Parse Time
        • Second
        • Time In
        • Year
        • Year Day
      • 🟦Text
        • Concat
        • Contains
        • Ends With
        • Execute Template
        • I Contains
        • I Ends With
        • I Starts With
        • Starts With
        • LTrim
        • RTrim
        • Replace
        • Regex Find All String
        • Regex Find String
        • Regex Match String
        • Trim
        • Text To Lower
        • Text To Upper
        • Text To Title
        • Url Getarg
      • 🟦Other
        • Assign
        • Run Custom
        • Redirect Web Page Event
        • Render Web Template Event
    • 🟧Variables
      • Array
      • Checkbox
      • Collection
      • Collection (Custom Model)
      • Collection (System Custom Model)
      • Custom Model
      • Date
      • Datetime
      • File
      • Json
      • Number
      • Number with decimal
      • Model
      • System Custom Model
      • Text
      • UUID
    • 🟪Webservices
  • Templates
    • Two sided marketplace template
      • Introduction
        • Part I: Installing and setting up the marketplace template
        • Part II: Understanding what features are included in the marketplace template
        • Part III: Customizing your marketplace frontend without coding
        • Exploring Dittofi's marketplace API
      • Listings
        • How to create a marketplace listing
    • How to build a CRUD app
  • Third Party APIs
    • OAuth 2.0 APIs
      • Introduction To OAuth 2.0
      • Google OAuth 2.0 - PART I
      • Google OAuth 2.0 - PART II
  • Dittofi Admin
    • Your Account
      • Workspace Admin
      • Manage Billing
      • Connect a custom domain
      • How to use a discount code to Dittofi Pro
  • FAQ
    • API Generator
    • How to write custom SQL?
    • Why does my image not display?
    • How can I set up Google Analytics?
    • Exporting and deploying my frontend code
    • What is a partial and what is a prefab?
    • How to set up a basic mulit tenant app on Dittofi
    • How to write a custom endpoint in Dittofi
    • How to integrate Font Awesome into Dittofi
    • How can I set up Dittofi to run on my own private server?
    • How to add roles such as Super Admin, Admin, Manager & User
    • How to prevent duplicate records being added to the database
    • What to do when relation cannot be created because their is violating data in the referenced table
  • Change Logs
    • Dittofi Change Logs
Powered by GitBook
On this page
  • Step 1: Create Export CSV Endpoint
  • Step 2. Create Export CSV Action
  • Step 3. Add a File Read Event
  • Step 4. Add a CSV Writer Event
  • Step 5. Build code and and Run

Was this helpful?

  1. Learn Backend
  2. Events
  3. Files

CSV Writer Event

An overview of how to configure the CSV Writer event in Dittofi

PreviousCSV Reader EventNextFile Read

Last updated 2 years ago

Was this helpful?

The CSV writer event lets you build in functionality to export data to a CSV format out of your app and write it to a file. You can set up the CSV writer event in five quick and easy steps.

  • Step 1. Create Export CSV Endpoint

  • Step 2. Create Export CSV Action

  • Step 3. Add a File Read Event

  • Step 4. Add a CSV Writer Event

  • Step 5. Build Code and Test

PLEASE NOTE

For the purpose of this example, we are going to be exporting data from inside a Data Model called "Addresses" which contains the following column headers, data types and data.

You can repeat the steps in this tutorial with whatever data set you're reading from your Data Models.

Step 1: Create Export CSV Endpoint

Next, set up the endpoint as below.

NOTICE

  • The "Request Method" option can be anything here and the endpoint does not need any variables set, unless of course you're looking to export of specific subset of records from your system.

  • The Res. Content Type (Response Content Type) is set to text/CSV.

Once you've filled in the endpoint values as above, save your Export CSV Endpoint and close it.

Step 2. Create Export CSV Action

Next, give your action the same name as your Export CSV Endpoint and set the Action Trigger to be the Export CSV Endpoint, as below.

Next, we need to add two events to our action. The first event is going to create a file on our server that we are going to write to and the second event is going to write data to that file.

Step 3. Add a File Read Event

The event that we need to use in order to create a file on our server is (rather unintuitively) the File Read Event. You can add this event to your action by clicking on the "+ Add Event" button below your actions and events graph.

The file read event has the following configuration:

Event Parameter
Description

File Path

The path of the file that we are going to read or in this case create. This can be passed in as a variable to our event.

As

This is a new variable that represents the file that the File Event is reading from.

Create New File

A check box that if check will allow the File Read Event to create a new file.

Prevent creating if already exists

A check box that if checked will prevent you from creating a new file if there is already a file at the location set by your File Path.

Write mode

There are two options here, Append or Overwrite.

If you have Append set here, this will mean that when you open the file any information that we are about to write to the file will Append to the existing file. Alternatively, if you have Overwrite set here, this will mean that when you open the file any information that we are about to write to the file will Overwrite the contents of that file.

For now, because we are looking to write data to a CSV file, let's configure the File read event in the following way.

Notice, because we are looking to write data to a CSV, we have created a variable called FilePath from inside our Export CSV Action. This variable has the following type, label, name and expression.

Step 4. Add a CSV Writer Event

Next, save your File Read Event and add the CSV Writer Event. This is going to be used to write data to the file that we just created in the File Read Event, as shown below.

To write data to the file, first we must find the address of the file. This can be done by looking up the File Variable that we created in our previous event, as shown below.

NOTE

The File Variable that we add above, is the file that we created as our As Variable when we added the File Read Event in Step 3 above.

Next, we set the With Header parameter which tells us if we want to include a header with all of the column names in the CSV file that we are about to write. This parameter can either be true or false and to set it, we need to first create a new variable of type Check Box from within our action.

And second, (if we want to include a header within our CSV file) we can map the trueCheckbox Variable to our With Header parameter as below.

Lastly, the Object Parameter is the actual set of information that we want to write to the file. As we mentioned at the start of this tutorial this is our Addresses Data Model, shown again below.

To access this data from within our CSV Writer Event, we need to first create a new variable called "Addresses" and of type Collection, as below.

Second, we can associate this variable with our CSV Write Events Object Parameter.

Save your CSV Write Event and then (lastly), set the response variable in your action to your File variable. This is going to be the file that you're writing to.

Step 5. Build code and and Run

Notice, the data that is returned from your Export CSV Action is contained within the Endpoint Response body, as shown below.

To actually see the file download, you need to take the URL path for your Export CSV Endpoint and copy it into another tab, as shown below.

You can create an Export CSV Endpoint from inside the Export CSV Endpoints tab. To do this, head on over to the Export CSV Endpoint and click on .

By itself your Export CSV Endpoint does nothing. To give it functionality, we need to create an Export CSV Action and associate that action with our Export CSV Endpoint. To create an Export CSV Action, head on over to the actions tab and create a new action by clicking on .

The final steps are to (1) build your code and (2) test your CSV Export Endpoint. To build your code, click on . Once the code has built, you can test this from within your Export CSV Endpoint, as below.

🟥
🟦