Category: How do I do X?
Updated

This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

Buttons in Email

Issue

I want to add a button in my email query that can change a column in a row of a spreadsheet attached. Specifically, I want to have an "approve" and "deny" button in the email that changes the approval column of a product order to say approved or denied.

Resolution

The solution involves adding an HTML button to the email query that opens an Appsmith app with a query parameter containing the ID of the row to approve. The Appsmith app can then use this ID to change the approval column of that product order to say approved or denied.

To implement this solution, you will need to create an Appsmith app that includes a database query to update the approval column of a row based on the ID passed in the query parameter. You can then embed this app in the email using an HTML button that links to the app with the appropriate query parameter.

Here is an example of how to create the HTML button to link to the Appsmith app:

<a href="https://appsmith.com/approve?id={ROW_ID}">
<button>Approve</button>
</a>

Replace {ROW_ID} with the ID of the row to approve.

On the Appsmith side, you will need to use the onPageLoad function to read the query parameter and update the database accordingly. Here's an example of how to do this using JavaScript:

function onPageLoad() {
const rowId = new URLSearchParams(window.location.search).get("id");

// TODO: Update database with approval status for rowId
}

Replace the TODO comment with the code to update the database.

With these changes, the email query will include buttons that link to the Appsmith app with the appropriate query parameter. Clicking the button will open the app and trigger the onPageLoad function, which will update the status of the row in the database.