---
updatedAt: 2025-09-17T22:29:10.000Z
agentTools:
  projectIndex: https://docs.vizionapi.com/llms.txt
---

# Map Vizion milestones to TMS events using DCSA event and location codes

```javascript JavaScript
const tms_events = {
  // Empty out for stuffing
  EOS: {
      event_classifier: "ACT",
      journey_type: "EQUIPMENT",
      transport_mode: null, 
      facility_type: null, 
      empty_indicator: "EMPTY",
      event_type: "GTOT",
      shipment_location: ["PRE", "POL"]
  },

  // Gate in full at origin port
  IGT: {
      event_classifier: "ACT",
      journey_type: "EQUIPMENT",
      transport_mode: null, 
      facility_type: null, 
      empty_indicator: "LADEN",
      event_type: "GTIN",
      shipment_location: "POL"
  },

  // Container loaded on vessel at origin port
  COV: {
      event_classifier: "ACT",
      journey_type: "EQUIPMENT",
      transport_mode: null, 
      facility_type: null, 
      empty_indicator: "LADEN",
      event_type: "GTIN",
      shipment_location: "POL"
  },

  // Vessel departure from the origin port
  VDO: {
      event_classifier: "ACT",
      journey_type: "TRANSPORT",
      transport_mode: "VESSEL",
      facility_type: null,
      event_type: "DEPA",
      shipment_location: "POL"
  },

  // Vessel ETA to port of discharge
  ETA: {
      event_classifier: "EST",
      journey_type: "TRANSPORT",
      transport_mode: "VESSEL",
      facility_type: null,
      event_type: "ARRI",
      shipment_location: "POD"
  },

  // Vessel arrival at port of discharge
  VAU: {
      event_classifier: "ACT",
      journey_type: "TRANSPORT",
      transport_mode: "VESSEL",
      facility_type: null,
      event_type: "ARRI",
      shipment_location: "POD"
  },

  // Container discharged from vessel at port of discharge
  CDU: {
      event_classifier: "ACT",
      journey_type: "EQUIPMENT",
      transport_mode: null, 
      facility_type: null, 
      empty_indicator: "LADEN",
      event_type: "DISC",
      shipment_location: "POD"
  },

  // Container outgates from port of discharge
  COU: {
      event_classifier: "ACT",
      journey_type: "EQUIPMENT",
      transport_mode: null, 
      facility_type: null, 
      empty_indicator: "LADEN",
      event_type: "GTOT",
      shipment_location: "POD"
  },

  // Container is available for pickup
  APU: {
      description: "Container available for pickup",
      shipment_location: ["POD", "PDE"]
  },

  // Last free day
  LFD: {
      description: "Free time to expire",
      shipment_location: ["POD", "PDE"]
  },

  // Container has arrived at place of delivery
  CAD: {
    event_classifier: "ACT",
    journey_type: "TRANSPORT",
    transport_mode: null, 
    facility_type: null, 
    event_type: "ARRI",
    shipment_location: "PDE"
  },

  // Container has out-gated from the place of delivery
  COD: {
    event_classifier: "ACT",
    journey_type: "EQUIPMENT",
    transport_mode: null, 
    facility_type: null, 
    empty_indicator: "LADEN",
    event_type: "GTOT",
    shipment_location: "PDE"
  },

  // Empty container returned
  ECR: {
      event_classifier: "ACT",
      journey_type: "EQUIPMENT",
      transport_mode: null, 
      facility_type: null, 
      empty_indicator: "EMPTY",
      event_type: "GTIN",
      shipment_location: null
  }
}

const referenceId = 'c294af9f-2107-4183-913a-721b210d5175'; // Replace with the reference ID you want to retrieve most recent update for

function writeToTMS(tms_code, location, timestamp, source) {
  console.log(`${tms_code} at ${location}: ${timestamp} (${source})`);
}

const matchMilestonesWithEvents = (tms_events, milestones) => {
  for (const milestone of milestones) {
      for (const [tms_code, tms_event] of Object.entries(tms_events)) {
          if (tms_event.description) {
              if (milestone.description === tms_event.description) {
                writeToTMS(tms_code, milestone.location.smdg_cd || milestone.location.bic_cd || milestone.location.unlocode, milestone.timestamp, milestone.source);
              }
          } else {
              const { journey_event } = milestone;
              if (
                  (!tms_event.event_classifier || tms_event.event_classifier === journey_event?.event_classifier) &&
                  (!tms_event.journey_type || tms_event.journey_type === journey_event?.journey_type) &&
                  (!tms_event.transport_mode || tms_event.transport_mode === journey_event?.transport_mode) &&
                  (!tms_event.facility_type || tms_event.facility_type === journey_event?.facility_type) &&
                  (!tms_event.empty_indicator || tms_event.empty_indicator === journey_event?.empty_indicator) &&
                  (!tms_event.event_type || tms_event.event_type === journey_event?.event_type) &&
                  (!tms_event.shipment_location || (Array.isArray(tms_event.shipment_location) ?
                      tms_event.shipment_location.includes(milestone.shipment_location.type_code) :
                      tms_event.shipment_location === milestone.shipment_location.type_code))
              ) {
                writeToTMS(tms_code, milestone.location.smdg_cd || milestone.location.bic_cd || milestone.location.unlocode, milestone.timestamp, milestone.source);
              }
          }
      }
  }
}

async function retrieveLatestReferenceUpdate() {
  try {
    const response = await axios.get(`${apiUrl}/references/${referenceId}/updates`, {
      params: {
        include_metadata: true,
        page: 1,
        limit: perPage,
      },
      headers: {
        'X-API-Key': apiKey,
      },
    });

    const { data } = response.data;

    // Process the data here (you can do whatever you need with the data)

    if (data.length > 0) {
      const latestUpdate = data[0]; 
      console.log('Latest reference update:', latestUpdate);

       // Call matchMilestonesWithEvents with the milestones
       matchMilestonesWithEvents(tms_events, milestones);
      // Access the milestones directly from the latest update payload
      const milestones = latestUpdate.payload.milestones;

    } else {
      console.log('No updates found for the reference ID:', referenceId);
    }
  } catch (error) {
    console.error('Error retrieving latest reference update:', error.message);
  }
}

retrieveLatestReferenceUpdate();



```

```json Response Example
{"success":true}
```

# Definition of TMS events

<!-- javascript@1-130 -->

Events in your TMS that you want to map to Vizion milestones. In this example, that includes eight core ocean milestones, "Available for pickup", "Last free day", arrival & gate out from inland destination.

# Set reference ID

<!-- javascript@132 -->

Replace with your reference ID

# Define function to write to your TMS

<!-- javascript@134-136 -->

This function demonstrates where in the code you could write the data back to your TMS.

# Define function to match TMS events to Vizion milestones

<!-- javascript@138-164 -->

This function iterates over TMS events and Vizion milestones, checking if there's a match. When a match is found, it calls the writeToTMS function to log information about the corresponding event.

# Retrieve latest reference update to pass to matchMilestonesWithEvents function

<!-- javascript@165-199 -->

The retrieveLatestReferenceUpdate function fetches the latest update for the defined reference ID. If an update is found, it calls matchMilestonesWithEvents with the fetched milestones.