Exercise #4 – Scripting and Dispatch Panel tips

Learn how scripting can streamline and automate dispatch business processes, saving businesses time and money. You’ll also explore a couple more features of the dispatch panel.

Note: This exercise builds on the previous three, so we recommend using the same Vehicle Tracker application and completing the exercises in order. You can see Exercise 1 here, Exercise 2 here, and Exercise 3 here.


Scripts can automate many dispatching processes, which means fewer chances for human error and large time savings. Today, we’ll create and test a timer script that dispatches all planned jobs. Businesses could use this to automate dispatching of jobs to their mobile workforce early each morning.

Be sure that you have the latest Dispatch 5 and Updatev5 versions. For this more advanced exercise, you will also need to check your permissions. Enable the following permissions for the selected testing application (SiteAdmin > Search and Manageselect the app, and choose Privileges and Features):

  • • Events > _EditScriptExpression
  • • Login > _WebServiceScriptLogin
  • • All permissions in the ScriptApp folder
  • • All permissions in the Plugins > Dispatch folder

Create an Event Script

Login to the same Vehicle Tracker application you used for Exercise 1-3 as an admin user.

Pre-work: Create a few jobs with worker = Exercise1Worker (your worker from our first exercise) and date = today. These should show with state = Planned. Our script will allow you to automatically dispatch them.

1. Go to Development > App Builder.

2. Click + New App.

3. Name your app and choose the roles with access to it.

4. In 2. Click Scripts, click + New Click Script.

5. Name the click script, and select Timer in the Kind menu. For Next Execution, select an earlier time today (e.g. 4:00am with today’s date), and enter a schedule if you would like.

6. Click Edit next to Script.

7. Paste in the javascript below, replacing the current text in the editor.

var users = directory.getUsers();
var jobs;
var routes;
if (users != null) {
 for (var i = 0; i < users.length; i++) {
      jobs = dispatch.getPlannedJobs(users<i>.id, new Date());
      for (var j = 0; j < jobs.length; j++) {
      routes = dispatch.getPlannedRoutes(users<i>.id, new Date());
      for (var j = 0; j < routes.length; j++) {

8. Test the script by clicking > Run Script and then click Save.

9. Click Save again on the Edit App page.

Your timer click script is now complete.  You will now see your saved script in the App Builder window. You should also see that the jobs for Exercise1Worker now show in yellow with state = Dispatched. If you are signed into the Dispatch mobile app with your Exercise1Worker, you will also receive job notifications. 

Dispatch Panel

The Dispatch panel allows you to see much more than just the list of workers and their job/route status.

  • See job locations for each worker at glance.
  • Drill into a worker to see details about their routes and jobs for the day.

The worker detail popup window is fully responsive. Be sure to try resizing the window and choosing the data columns to customize your workspace. Let’s click around to see some of the new Dispatch panel functionality.

Job Locations at a Glance

Click on the pin icon on the right-hand side of a field worker row to see the location of all of their jobs. This works for jobs with worker Unassigned, and also for those currently assigned or dispatched to a worker. 

Work / Job List Drilldown

For routes with lots of stops, or an abundance of jobs for a particular day, you may want to see many more jobs at a glance than you can via the Dispatch Panel rows.

    • Click the hamburger icon on the right-hand side of a field worker row to see a full job list for the field worker. You can also do this in the Unassigned jobs row.

    • Right-click the header row in the new window to customize the columns shown.
    • Change the column width by hovering your mouse on the column border until your curser shows arrows. Click when the arrows are showing and drag to resize a column.
    • Use the Resize to fit and the Force fit columns menu options to have the system auto-select column widths for you based on the window width.

    • Change the window size by using the drag feature in the bottom right corner of the window to resize.
    • Print a full job list with your chosen columns.

Congrats! You just learned how to optimize routes and report on Dispatch activity, which are both key for reducing costs. The next exercise is focused on advanced activity within Dispatch, such as scripting.