Delete variable data from a device

Learn how to use an HTML Canvas widget to delete variable data from a device within a selected time window in Dynamic Dashboards.

Use this example to build an HTML Canvas widget that deletes a device variable's values within a selected time window.

  • Create the structure. Paste the following into the HTML code editor tab:

<div>
    <p id="token"></p>
    <p id="selectedDeviceID"></p>
	<p id="selectedDeviceLabel"></p>
	<select id = "labels"></select>
	<form id="date-form">
		<label for="date1">Start date:</label>
		<input type="datetime-local" id="date1" name="date1" value="2023-01-01T00:00" required>
		<br>
		<label for="date2">End date:</label>
		<input type="datetime-local" id="date2" name="date2" value="2023-01-01T12:00" required>		
		<br>
		<button type="submit">Delete values</button>
	</form>
</div>
  • Paste the following into the CSS code editor tab:

    body {
      font-family: Arial, sans-serif;
      max-width: 400px;
      margin: 0 auto;
      padding: 2rem;
    }
    
    form {
      display: flex;
      flex-direction: column;
    }
    
    label, input {
      margin-bottom: 1rem;
    }
    
    button {
      cursor: pointer;
      background-color: #0077cc;
      color: white;
      padding: 0.5rem 1rem;
      border: none;
      border-radius: 4px;
      font-size: 1rem;
      font-weight: bold;
    }
    
    button:hover {
      background-color: #005aa3;
    }
  • Paste the following into the JavaScript code editor tab:

The result is a widget like this:

Use the dropdown to select a variable from the current device in the Dynamic Dashboard. Then choose a time window with the date pickers.

When you click Delete values, Ubidots deletes that variable's data for the selected time window.

Ubidots runs this action asynchronously. You may need to wait a few minutes before the values disappear.

Last updated

Was this helpful?