Tutorial 4 - Automatically create a job when a contact is added

Learn how to use Get Record, Choice, Variables, Geocode Address, Find Closest Region, and Create Job to automatically create and place a job when a new contact record is inserted.

Overview

Scenario

You work for a home care organization. When a care coordinator registers a new client as a contact record in Skedulo, your team wants a needs assessment job automatically created so it can be picked up and scheduled promptly. Not every account should trigger this behavior: vendor accounts and referral partners should not create jobs: so each account has an AccountType field that classifies what kind of account it is.

This automation handles the whole process without any manual intervention: it checks the account type, geocodes the client’s address to find the right region, and creates the job linked to the account, contact, and region.

What the automation does

In this tutorial you will create an automation that automatically creates a job whenever a new contact record is inserted. The automation will:

  1. Load the contact’s parent account record to read a custom field, using the Get Record action.
  2. Check whether the account’s AccountType is Client, using a Choice step.
  3. Build a single address string from the contact’s individual address fields, using a Variables step.
  4. Geocode the contact’s address to obtain latitude and longitude coordinates.
  5. Find the closest region to the geocoded coordinates.
  6. Create the job and link it to the account, contact, and region.

This tutorial introduces several new concepts: the Get Record action for loading a related record, the Variables step for preparing reusable values, conditional branching with the Choice step, and chaining step outputs together across multiple actions.

By the end of this tutorial you will have:

  • Created an automation triggered by a contact insert, filtered to contacts that have a parent account
  • Used the Get Record action to load a related Account record and make its fields available in the workflow
  • Added a Choice step to conditionally branch based on the account’s AccountType picklist value
  • Used a Variables step to build a reusable address string from the contact’s individual address fields
  • Used the Geocode Address action to convert the address to coordinates
  • Used the Find Closest Region action to identify the best region for the job
  • Used the Create Job action to create a job linked to the account, contact, and region
  • Tested the automation and verified the job was created

Prerequisites

  • You must have the Administrator role, or a role that includes the “Modify webhooks and triggered actions” permission.
  • You should be familiar with the automation builder UI. If not, read Get to know the automation builder UI first.
  • Completing Tutorial 1, Tutorial 2, and Tutorial 3 first is recommended.
  • The Account object must have a picklist custom field named AccountType. If this field does not yet exist, create it before proceeding, see Manage custom fields for instructions.

Configure the AccountType field with the following properties:

Property Value
Field name AccountType
Field type Picklist (single-select)
Options Client, Referrer, Vendor, Partner
  • Client: a care recipient. Contacts linked to a Client account will have a needs assessment job created automatically.
  • Referrer: a GP surgery, hospital, or social worker who refers clients to the organization. No job is created.
  • Vendor: a supplier of equipment or consumables. No job is created.
  • Partner: another care organization or subcontractor. No job is created.

Step 1: Create a new automation

  1. In the web app, navigate to Settings > Configuration tools > Automations.
  2. Click New automation.
  3. In the New automation dialog, enter a Name for the automation, for example:
    Tutorial 4 - Create job for new contact
    
  4. Optionally, enter a Description such as:
    Automatically creates a needs assessment job when a new contact is inserted under a Client account.
    
  5. Select the Record Modified template.
  6. Click OK to continue to the automation builder.

The automation builder opens with a default trigger step and is pre-populated with an Echo action by default.


Step 2: Configure the trigger

The trigger will fire whenever a Contact record is inserted. You will configure it to respond to Insert operations only, and add a filter that stops the automation from running when the new contact has no parent account. The account is needed later in the workflow: both to check the custom flag and to link to the new job: so there is no point proceeding without one.

The trigger step properties panel

  1. On the workflow canvas, click the Trigger step (the blue rectangle). The step properties panel opens on the right.
  2. Under the Trigger section, find the Object type field and select Contacts from the dropdown.
  3. Under Operations, enable the Insert checkbox only. Make sure the Update and Delete checkboxes are cleared.
  4. Under Run when, click Advanced and enter the following EQL expression:
    Current.AccountId != null
    

This filter ensures the automation only starts for contacts that are linked to an account. Contacts without a parent account are excluded at the trigger level, before any workflow steps run.


Step 3: Replace the Echo action with a Get Record action

The template pre-populates an Echo action as a placeholder. The first real step in this workflow is to load the Account record associated with the new contact, so that you can read the AccountType custom field from it.

The trigger fires on a Contact insert and makes the Contact’s own fields available as workflow variables: but it does not automatically load the fields of related records such as the Account. The Get Record action fetches a specific record by ID and makes the fields you request available as variables for the rest of the workflow.

Remove the Echo step

  1. On the workflow canvas, click the Echo step to select it.
  2. Delete it by pressing the Delete key, clicking the trash icon in the top right corner of the step, or clicking Delete step in the step properties panel.

Add and configure the Get Record step

  1. In the Steps palette on the left, locate the Get Record action. Type get in the search box to find it.
  2. Drag the Get Record step from the palette onto the workflow canvas and drop it onto the placeholder below the trigger step.
  3. Click the Get Record step to open its properties.
  4. In the Object type field, select Accounts.
  5. In the Id field, enter:
    $trigger.current.AccountId
    
  6. In the Fields section, click + Add field and select AccountType.

The Get Record action only returns the fields you explicitly request: it does not load every field on the record. In this workflow you only need the AccountType field, so that is the only field to add here. If you need additional Account fields later in the workflow, add them now.

The output of the Get Record step is stored in the $getRecord variable. Requested fields are accessed via the path $getRecord.result.data.{fieldName}: in this case, $getRecord.result.data.AccountType.


Step 4: Add and configure the Choice step

With the Account record loaded, you can now add the Choice step that branches the workflow based on whether the account is classified as a client.

The Choice step properties panel

Add the step

  1. In the Steps palette, locate the Choice step. Type choice in the search box to find it.
  2. Drag the Choice step onto the canvas and drop it below the Get Record step.

Configure the step

  1. Click the Choice step to open its properties. The step starts with a single branch for you to configure.

  2. In the branch, set the Label (optional) field to:

    Is Client
    
  3. In the Condition for that branch, click Use expression → to switch from the no-code builder to a raw expression, and enter the following JSONata expression:

    $getRecord.result.data.AccountType = 'Client'
    

    This reads the AccountType field from the Account record loaded in Step 3 and checks whether its value is Client.

    If the value is Client, the workflow will follow the Is Client branch. For any other value: Referrer, Vendor, Partner, or an unset field: the workflow will follow the default branch and complete without creating a job.

  4. Enable Include else (default) branch, and set its Then go to to End successfully (Succeed).

All remaining steps: Variables, Geocode Address, Find Closest Region, and Create Job: must be placed inside the Is Client branch.


Step 5: Add and configure a Variables step

The first step inside the Is Client branch builds the contact’s address as a single string. Rather than repeating the same concatenation expression in every step that needs it, you can define it once in a Variables step and reference the result by name for the rest of the workflow.

The Variables step properties panel

Add the step

  1. In the Steps palette, locate the Variables step. Type variables in the search box to find it.
  2. Drag the Variables step onto the canvas and drop it into the Is Client branch placeholder inside the Choice step.

Configure the step

  1. Click the Variables step to open its properties.
  2. Click + Add to create a new variable definition row.
  3. In the key field, enter:
    fullAddress
    
  4. In the value field, enter the following expression:
    $join([$trigger.current.MailingStreet, $trigger.current.MailingCity, $trigger.current.MailingState, $trigger.current.MailingPostalCode], ', ')
    

Step input fields in the automation builder, including variable values: support JSONata, a lightweight expression language for querying and transforming data. The $join function takes an array of values and a separator, and concatenates them into a single string. For a contact at 123 Main St, Springfield, IL 62701 the result would be:

123 Main St, Springfield, IL, 62701

The address string will be available in all subsequent steps as $fullAddress.


Step 6: Add and configure the Geocode Address action

Add the Geocode Address action inside the Is Client branch of the Choice step. This action takes the address string you prepared in the Variables step and returns the corresponding latitude and longitude coordinates.

The Geocode Address action properties panel

Add the step

  1. In the Steps palette, locate the Geocode Address action. Type geocode in the search box to find it.
  2. Drag the Geocode Address step onto the canvas and drop it into the Is Client branch placeholder inside the Choice step.

Configure the step

  1. Click the Geocode Address step to open its properties.
  2. In the Address field, enter:
    $fullAddress
    

This references the address string you defined in the Variables step, rather than repeating the concatenation expression here. If you need the full address string anywhere else in the workflow, for example, to set it on the new job: you can reference $fullAddress there too.

The Geocode Address action outputs the resolved coordinates. They are available in subsequent steps as $geocodeAddress.result.data.latitude and $geocodeAddress.result.data.longitude.


Step 7: Add and configure the Find Closest Region action

Add the Find Closest Region action immediately after the Geocode Address step, also inside the Is Client branch. This action uses the coordinates from the previous step to identify the most appropriate region for the new job.

The Find Closest Region action properties panel

Add the step

  1. In the Steps palette, locate the Find Closest Region action. Type region in the search box to find it.
  2. Drag the Find Closest Region step onto the canvas and drop it below the Geocode Address step, still inside the Is Client branch.

Configure the step

  1. Click the Find Closest Region step to open its properties.
  2. In the Latitude field, enter:
    $geocodeAddress.result.data.latitude
    
  3. In the Longitude field, enter:
    $geocodeAddress.result.data.longitude
    

The Find Closest Region action returns the ID of the best matching region, available in the next step as $findClosestRegion.result.data.UID.


Step 8: Add and configure the Create Job action

The final action in the Is Client branch is Create Job. This creates a new job record and links it to the account, contact, and region identified by the previous steps.

The Create Job action properties panel

Add the step

  1. In the Steps palette, locate the Create Job action. Type create job in the search box to find it.
  2. Drag the Create Job step onto the canvas and drop it below the Find Closest Region step, still inside the Is Client branch.

Configure the step

  1. Click the Create Job step to open its properties.

  2. In the Account Id field, enter:

    $trigger.current.AccountId
    
  3. In the Contact Id field, enter:

    $trigger.current.UID
    
  4. In the Region Id field, enter:

    $findClosestRegion.result.data.UID
    
  5. In the Description field, enter:

    'Initial needs assessment for: ' & $trigger.current.FirstName & ' ' & $trigger.current.LastName
    

    The & operator concatenates strings in JSONata: here it joins the static label with the new client’s first and last name to produce something like Initial needs assessment for: Jane Smith. See Working with strings for more string functions and patterns.

  6. In the Address field, enter:

    $fullAddress
    
  7. In the Geo Latitude field, enter:

    $geocodeAddress.result.data.latitude
    
  8. In the Geo Longitude field, enter:

    $geocodeAddress.result.data.longitude
    
  9. In the Duration field, enter:

    30
    

Setting the address and coordinates places the job on the map in the scheduling view. The duration of 30 minutes is a reasonable default for an initial needs assessment: adjust this to match your organization’s standard visit length.


Step 9: Activate the automation

  1. In the automation builder header, click Activate. This automation is currently a Draft: clicking Activate validates the whole workflow and makes it live in one step. If you’d rather leave it as a draft for now, click Save as Draft instead, and activate it later from the automation detail page.
  2. If there are any configuration errors, they will be highlighted in the builder. Resolve them and click Activate again.
  3. Once saved successfully, click the Close button to leave the automation builder. You will be shown the automation detail page for the automation you just created, now showing a status of Active.

The automation will fire the next time a contact with a parent account is inserted.


Step 10: Create a test contact to trigger the automation

To test the automation, create a contact with a complete address, linked to an account that has AccountType set to Client.

Prepare the test account

Before creating the contact, confirm that the account you plan to use has AccountType set to Client. If you are unsure how to set a custom field on an account record, refer to Manage custom fields.

Create the test contact

  1. Use the Quick create button in the main navigation bar at the top of the page. It’s the white button with the + plus sign in it.
  2. Click + Contact in the menu.
  3. On the contact create page, fill in the required fields and enter a complete address, including Street, City, State, Postal Code, and Country.
  4. In the Account field, link the contact to the account you prepared above.
  5. Save the contact.

Creating the contact fires an Insert operation on the Contacts object. Because the contact has a parent account (AccountId != null), the trigger filter matches and the workflow starts. The workflow loads the account, builds the address string, evaluates the AccountType field, and: since it is Client: proceeds to geocode the address, find the closest region, and create a job.


Step 11: Verify the job was created

First confirm the automation ran by checking the activity log, then verify that a job was created and linked correctly.

Check the activity log

After creating the contact, navigate to Settings > Configuration tools > Automations and click the name of the Tutorial 4 - Create job for new contact entry.

The automation activity tab

  1. Click the Activity tab.
  2. Each row represents one workflow execution. Click the most recent (topmost) row to expand it and see the individual step messages for that run.

You should see entries similar to:

Timestamp Event type Status Message
{date/time} Trigger Info Automation workflow started
{date/time} Workflow Info Started action ‘get-record’: Get a Accounts record
{date/time} Workflow Info Completed action ‘get-record’: Get a Accounts record
{date/time} Workflow Info Started action ‘geocode-address’: Geocode address: 123 Main St, Springfield, IL, 62701
{date/time} Workflow Info Completed action ‘geocode-address’: Geocode address: 123 Main St, Springfield, IL, 62701
{date/time} Workflow Info Started action ‘find-closest-region’: Find closest region to (39.7817, -89.6501)
{date/time} Workflow Info Completed action ‘find-closest-region’: Find closest region to (39.7817, -89.6501)
{date/time} Workflow Info Started action ‘create-job’: Create a job in region {region-id}
{date/time} Workflow Info Completed action ‘create-job’: Create a job in region {region-id}
{date/time} Workflow Info Automation workflow completed successfully

Note the entries within an expanded execution are ordered oldest to newest, showing the order the steps actually ran in.

Verify the job record

  1. Navigate to the Jobs list and locate the job that was just created.
  2. Open the job and confirm that:
    • The Account field is linked to the account you used for the test.
    • The Contact field is linked to the contact you just created.
    • The Region field is populated with the region returned by the Find Closest Region action.
    • The Description field shows the client’s name.
    • The job is placed on the map at the contact’s address.

You should be able to see from the log and the job record that:

  • The trigger detected the new contact and confirmed it had a parent account
  • The Get Record action loaded the parent Account’s AccountType field
  • The Choice step evaluated AccountType, found Client, and followed the Is Client branch
  • The Variables step built the address string from the contact’s address fields
  • The Geocode Address action resolved the address to coordinates
  • The Find Closest Region action identified an appropriate region from those coordinates
  • The Create Job action created a new job linked to the account, contact, and region
  • The workflow completed successfully

What you learned

In this tutorial you:

  • Configured a trigger filter to exclude contacts that have no parent account
  • Used the Get Record action to load a related Account record and make its fields available in the workflow
  • Used a Variables step to define a reusable address string, avoiding repeated expressions across multiple steps
  • Used a Choice step to conditionally branch the workflow based on a picklist field value
  • Used the Geocode Address action to convert an address string to coordinates
  • Used the Find Closest Region action to identify an appropriate region from coordinates
  • Used the Create Job action to create a job linked to an account, contact, and region
  • Chained step outputs together across multiple sequential actions

Next steps

  • Experiment with the Else branch of the Choice step, for example, add an Echo action to log a message when a contact is inserted for a non-Client account.
  • Explore the full list of available actions in the Action reference guide.