Sample production request form

Generate a production request form for a particular product using Google Docs

Explanation

Using a combination of GraphQL and Javascript in Google Docs and Apps Script you can populate fields for a production request form using fields that retrieve Work and Product level information. Note that some of these fields will require a production run to exist in Consonance in order to populate.

Setting Up the Sidebar in Google Docs:

  • Open a new Google Docs document.

  • Navigate to Extensions > Apps Script.

  • In the Apps Script Editor, click the plus icon (+) next to "Files" and create a new HTML file named 'sidebar'.

  • Copy and paste the HTML code below to create an interactive sidebar, replacing any placeholder text that already exists in the new file. This sidebar, accessible from the main navigation of your document, includes a form for inputting an ISBN, URL, and API key. The sidebar can be customised with CSS.

<!DOCTYPE html>
<html>
  <head>
    <base target="_top">
        <!--link href='https://fonts.googleapis.com/css?family=Open+Sans:400,600,300' rel='stylesheet' type='text/css'-->
    <link href='open-sans.css' rel='stylesheet' type='text/css'>
    <style type="text/css">
        * {
            font-family: 'Open Sans';
            font-style: normal;
            font-size: 13px;
        }
        .light { 
            font-weight: 300;
        }
        .regular { 
            font-weight: 400;
        }
        .semibold { 
            font-weight: 600;
        }
    </style>
  </head>
  <body>
    <p>
      Please type in the URL, Key, and ISBN13 that you want, and choose Find.
    <ul>
      <li>URL is usually https://web.consonance.app</li>
      <li>Key will be your API that you get by emailing support@consonance.app</li>
      <li>ISBN is something like 9781905005123</li>
    </ul>
    </p>
    <form id="isbnGetter">
      <p class="semibold">
        <label>Consonance URL</label>
        <br />
        <input type="text" value="https://web.consonance.app" id="url" name="url">
      </p>
      <p class="semibold">
        <label>Key</label>
        <br/>
        <input type="text" value="" id="key" name="key">
      </p>
      <p class="semibold">
        <label>ISBN</label>
        <br/>
        <input type="text" value="" id="isbn13" name="isbn13">
       </p>
      <input type="button" value="Find" onclick="google.script.run.main(isbnGetter)">
    </form>
  </body>
</html>

Creating the Main Script:

  • In the Script Editor, select Code.gs from the file section. Google might have called it something else, but there will only be one file with the .gs extension, so that's the one to select.

  • Copy and paste the JavaScript code below into this file. This code includes functions for opening the sidebar, sending GraphQL queries, and populating your Google Doc with the fetched data.

  • Optionally, replace placeholders like YOUR_API_KEY with actual values provided by Consonance support.

Save the file. The top of the page should look like this, with onOpen selected:

Creating a template:

Type and format words as you'd usually do into the doc (not the script). The words that can be swapped out using the example we've given here are the ones in red in this screenshot:

e.g. type IMPRINTNAME_ into your doc to have it replaced with the imprint's name.

You can edit the script if you prefer different names, and add other queries.

Using Your Custom Production Request Form:

  • Back in your Google Docs document, a new menu item "Consonance" will appear in the main navigation bar.

  • Click on it and select the option to open the sidebar.

  • Fill out the form in the sidebar with the required information (URL, API Key, ISBN) and click "Find" to auto-populate the production request form.

Here is an example of how your Google doc might look before the script runs.

Google Docs screenshot. The document has the heading Consonance Production Request Form and has many fields that are unpopulated.

This is how it might look after choosing the 'Find' button.

Google Docs screenshot. The previously unpopulated fields now have relevant information retrieved from Consonance.

Troubleshooting

If you are signed in to more than one Google account, this can apparently mess things up, so try signing out of all but one account if the Find button doesn't change anything.

You'll probably be prompted to authenticate: click OK on dialogue boxes that prompt you.

Raise a support ticket to get your API key at support@consonance.app.

Raise a ticket if you'd like us to share a starter template with you.

Last updated