# Global Scripts

**URL:** <https://community.quickfile.co.uk/t/global-scripts/9117>\
**Category:** Advanced Customisation\
**Created:** [17 October 2015 21:34 UTC](https://community.quickfile.co.uk/t/global-scripts/9117 "2015-10-17T21:34:48Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Glenn](https://qfcommunity.b-cdn.net/user_avatar/community.quickfile.co.uk/glenn/32/26841_2.png) [@Glenn](https://community.quickfile.co.uk/u/Glenn)\
**Post date:** [17 October 2015 21:34 UTC](https://community.quickfile.co.uk/t/global-scripts/9117/1 "2015-10-17T21:34:48Z")

</div>

**Access via:** Account Settings › Design Customisation › Advanced CSS & HTML Customisation › **Custom Scripts** (left-hand list)

# Prefer to watch?

[![Watch Customise QuickFile with CSS, HTML and scripts on YouTube](https://qfassets.b-cdn.net/original/3X/0/4/042c01bf58fa94b18fe4e71ede57a1d5d1d97f4a.png)](https://www.youtube.com/watch?v=BYgxD78X9j4)

Prefer a video walkthrough? Watch our [Customise QuickFile with CSS, HTML and scripts](https://www.youtube.com/watch?v=BYgxD78X9j4) tutorial on the QuickFile Help Guides YouTube channel.

# Introduction

Global Scripts (called **Custom Scripts** in the editor) runs your own JavaScript on every page of your QuickFile admin area. Use it to automate small tasks, such as ticking a box you always tick or clearing a field you always change.

> **Admin area only:** scripts don’t run in the client area, so your clients never see them.

# What’s available

- Plain JavaScript and **jQuery 2.0** , which is already loaded, so you can use `$` straight away.
- Your script runs after the page has loaded.
- Each page’s `<body>` has a class that names it, so you can run code on one page only:

| Page | Body class |
| --- | --- |
| Dashboard | `.page-dashboard-index` |
| Sales invoice view / send | `.page-sales-preview` |
| New purchase | `.page-purchases-create` |
| Bank statement | `.page-bank-statement` |

To find the class for any other page, press F12 and look at the `<body>` tag.

# The safe pattern

Wrap each snippet like this. It only runs on the page it’s meant for, and an error won’t affect other pages:

```js
$(function () {
    try {
        if ($("body").hasClass("page-sales-preview")) {
            // your code for the invoice view / send page
        }
    } catch (e) {
        console.warn("Custom script error:", e);
    }
});

```

# Recipe 1: Pre-tick options when sending an invoice

When you open the send panel on an invoice, this ticks **CC me** and **Add due date to my calendar** for you:

```js
$(function () {
    if (!$("body").hasClass("page-sales-preview")) return;
    $("#chkCcMe").prop("checked", true).trigger("change");
    $(".chkcal_reminder").prop("checked", true).trigger("change");
});

```

 ![The send panel with CC me ticked by Recipe 1. Client details are replaced with samples.](https://qfassets.b-cdn.net/original/3X/b/0/b04932d165065f2700935c92c53807895c4d259f.jpeg)

# Recipe 2: Choose purchase dates yourself

Clears the receipt date and due date on a **new** purchase, so you can’t save today’s date by mistake:

```js
$(function () {
    if (!$("body").hasClass("page-purchases-create")) return;
    // Don't clear dates when an existing purchase is opened for editing
    if (/ID=/i.test(location.search)) return;

    $("#tblstaticInvoiceSettings #txtreceiptDate").val("");
    $("#tblstaticInvoiceSettings #txtdueDate").val("");
});

```

> **Test this on your own account first:** make sure dates are still there when you edit an existing purchase.

# Good practice

- **Undo quickly:** if a script breaks a page, deactivate Custom Scripts.
- **Debug:** press F12 and open **Console** to see errors and your `console.log` output.
- **Only use scripts you understand.** They run with full access to your account.
- Share useful scripts on the [QuickFile community forum](https://community.quickfile.co.uk).

# Related topics

New to Advanced Customisation? Start with **Advanced Customisation Tools** for an overview of every template, plus troubleshooting tips.

- [Advanced Customisation Tools](https://support.quickfile.co.uk/t/advanced-customisation-tools/8943): Where to find the editor, what each template changes, and how save, preview and activate work. Includes troubleshooting.
- [Global CSS template](https://support.quickfile.co.uk/t/global-css-template/8955): Change how QuickFile looks for you and your team.
