Creating an Event and Action that copies Asset's Zone to WO's UDF
Update Work Order UDFChar1 when the Asset is set or changed

This tutorial shows how to build an Event and Action (E&A) that copies the selected Asset's Zone into the Work Order field UDFChar1.

This setup is based on the Work Order Asset Change trigger. That means it runs when the Asset is first set on a new Work Order and when the Asset is changed later. It does not run for unrelated Work Order edits where the Asset value stays the same.

Download the finished event

If you want a reference export while following the steps, use this file:

Download the finished Event and Action export

If you do, you can import it from the 3 dot menu in the Events and Actions module

What this event does

By the end of this tutorial, your event will:

  1. Detect when the Work Order Asset is assigned or changed.
  2. Read the ZoneName from that Asset.
  3. Write the ZoneName into WorkOrder.UDFChar1.

Before you start

  1. Make sure you can open the Events and Actions module and create or edit events.
  2. Confirm that UDFChar1 is the correct destination field on the Work Order. You don't want a test/learning exercise to wipe out real data!
  3. Have an Asset with a Zone available for testing.

Import or Build the E&A

Import the E&A

Shows where to import the Event and Action

OR build the event

  1. Open the Events and Actions module from the main menu.
shows the menu ui for getting to the events and actions
  1. Create a new event, then enter an ID and a name. Those fields are mandatory.
Shows where to enter the required fields
  1. Open the Workflow tab.
Shows position of Workflow tab
  1. Click + and add a Data trigger.
Shows the 2 steps to get the Data trigger
  1. Select the new trigger puck, then click the pencil icon to edit it.
Selected trigger puck with the edit pencil highlighted
  1. Give the trigger a useful name and comment, set Event Type to Work Order Asset Change, then save it with the green tick.
image.png Shows Trigger configuration with Work Order Asset Change selected
  1. Back in the workflow editor, click + again, then go to Actions -> Data -> Execute SQL.
Shows Workflow action picker with Execute SQL selected
  1. Connect the trigger to the SQL action by dragging handle 1 to handle 2.
Shows the 2 clicks required to join the trigger and the event
  1. Select the SQL action puck and click the pencil icon to edit it.
Shows UI to edit the event
  1. In the Parameters section, click Add.
Shows the Add button for parameters
  1. Create a parameter named WOPK and bind it to Data1.entityPK. This gives the SQL action the primary key of the Work Order being processed.
Parameter dialog showing WOPK bound to Data1.entityPK
  1. Create a second parameter for the Asset primary key. Name it NewAssetPK and bind it to Data1.currentValues.?
Shows choosingSecond parameter from dialog prepared for the new Asset PK
  1. After adding that binding, click Edit Expression so you can pull the AssetPK out of the bound object.
Shows where to click to get parameter editor with Edit Expression highlighted
  1. Use this expression, then save it with the green tick:
return bound["AssetPK"]
Shows typing in the JavaScript code
  1. In the Sql Statement field, paste the SQL below. You can use the ... button to expand the editor if needed.
UPDATE wo
SET wo.UDFChar1 = asset.ZoneName
FROM WO wo
LEFT JOIN Asset asset
    ON asset.AssetPK = @NewAssetPK
WHERE wo.WOPK = @WOPK
  AND (
      wo.AssetPK = @NewAssetPK
      OR (wo.AssetPK IS NULL
      AND @NewAssetPK IS NULL)
  );

The extra condition in the WHERE clause is a safety check. It makes sure the Work Order still points to the same Asset that triggered the event, which helps prevent an older async run from overwriting a newer change.

Execute SQL editor with the final statement entered
  1. Save the action. Then go back to the summary tab and tick Enabled so the event starts listening for Asset changes on Work Orders.
Show were to enable the Event and Action

Expected result

When a Work Order is created with an Asset, or when the Asset is changed later, UDFChar1 is updated to match that Asset's Zone Name.

If the Asset is removed from the Work Order and the trigger fires with a null AssetPK, this SQL will clear UDFChar1 as well.

Test it

  1. Create or open a Work Order.
  2. Assign an Asset that has a Zone.
  3. Save the Work Order and confirm that UDFChar1 now matches the Asset's Zone.
  4. Change the Asset to a different one and confirm that UDFChar1 updates again.