Skip to main content

Qrew Tip

  • November 19, 2025
  • 0 replies
  • 65 views
Maria
Forum|alt.badge.img+13

Watch Wes's update below to a Qrew Tip he made 2 years ago

Adding custom bulk updates to records from reports have never looked easier! In his example he uses the delete action to show child records being removed from a parent record while all tiers are visible on a report. Cool stuff!

Wes has graciously provided his secret sauce. You'll find the code he used at the bottom of this post.



Wes's Code provided below: 

The below code allows the adding of a custom delete option to appear on V3 reports (aka grid reports).

<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8" />
  <title>Bulk Delete</title>
  <script>
    async function deleteRecords() {
      try {
        // Parse query string
        const params = new URLSearchParams(window.location.search);
        const dbid = params.get("dbid");
        const apptoken = params.get("apptoken");
        const idsString = params.get("ids") || "";

        if (!dbid || !idsString) {
          alert("Missing dbid or ids parameter.");
          return;
        }

        // Parse "1;2;3" or "1,2,3" etc.
        const ids = idsString.split(/[;,]+/).map(id => id.trim()).filter(Boolean);

        // Loop through and delete each record
        for (const rid of ids) {
          const url = `${location.origin}/db/${dbid}?a=API_DeleteRecord&rid=${rid}${
            apptoken ? `&apptoken=${apptoken}` : ""
          }`;

          console.log("Deleting record:", rid);
          const resp = await fetch(url, { method: "POST" });
          const text = await resp.text();

          // Optional: check for errors
          if (!text.includes("<errcode>0</errcode>")) {
            console.warn(`Delete failed for rid=${rid}`);
          }
        }

        // After all deletes, go back to the previous page
        const prev = document.referrer;
        if (prev) {
          window.location.href = prev;
        } else {
          // fallback: go back in browser history
          window.history.back();
        }
      } catch (err) {
        console.error("Error during deletion:", err);
        alert("Error during deletion. See console for details.");
      }
    }

    window.addEventListener("DOMContentLoaded", deleteRecords);
  </script>
</head>
<body>
  <h3>Deleting</h3>
</body>
</html>