Inside the mysterious EVENT parm in CC tasks. Newbie needs help. How to access embedded object fields?

By looking at the RAW REQUEST section of a CC task in the invocation log, I can extract this JSON structure:

{
  "event": "cloudcode_asset_update_update_sql_asset",
  "server": "https://66bcbd3cfe5b0b7661d86.backend.us.journeyapps.com",
  "app": "66bccbac0d78980afd678",
  "app_id": "66bcbd3c6c27007214af4",
  "account_id": "66bccbac0d78007afd678",
  "sequence": 7439487125994602000,
  "operation": "update",
  "object": {
    "id": "023a92a7-4d7f-41d0-a07e-1e3bbeab0a04",
    "type": "asset",
    "updated_at": "2024-11-20T22:09:36Z",
    "sql_id_": 24870,
    "asset_tag": "03-0002",
    "category": {
      "key": "Asset",
      "display": "Asset"
    },
    "description": null,
    "serial_num": "121601",
    "status": {
      "key": "Installed",
      "display": "Installed"
    },
    "asset_type": "Ventilator, Adult / Pediatric",
    "campus": "Shore ",
    "dept": "333",
    "locdescr": null,
    "manuf": "Maquet",
    "model": "6447901",
    "site": null,
    "region": "MD",
    "qty_oh": null,
    "room": "room 1",
    "width": null,
    "depth": null,
    "height": null,
    "utilities": null,
    "condition": "Good",
    "q1": {
      "key": "Damaged",
      "display": "Damaged"
    },
    "q2": null,
    "asset_was_updated_in_AT": {
      "key": true,
      "display": "Yes"
    },
    "last_update": "2024-11-20",
    "updated_by": "Jaymer",
    "ps_dept_master_id": "92b4998e-af96-4d21-981c-d6eb4249fb3a",
    "ps_dept_master": {
      "id": "92b4998e-af96-4d21-981c-d6eb4249fb3a",
      "type": "dept_master",
      "updated_at": "2024-08-29T19:32:05Z",
      "display": "Level 1 - Cardiovascluar & Pulmonary",
      "department": "Level 1 - Cardiovascluar & Pulmonary",
      "ActiveYN": null,
      "ps_tenant_id": "47013944-72f8-4a59-84e6-8b89c53fe31f"
    },
    "ps_tenant_id": "47013944-72f8-4a59-84e6-8b89c53fe31f",
    "ps_tenant": {
      "id": "47013944-72f8-4a59-84e6-8b89c53fe31f",
      "type": "tenant",
      "updated_at": "2024-11-20T21:56:59Z",
      "display": "Bayview (bayview)",
      "abbrv": "bayview",
      "tenant_name": "JBayview",
      "image_base_path": "https://-",
      "logo_id": "834fe0f7-5c80-402e-915a-0e46959c7b27",
      "logo": {
        "state": "uploaded",
        "original": "https://...redacted...."
      },
      "logopath": "images/jh-bayview.png",
      "database": "market5",
      "project": 5
    }
  },
  "environment": "testing"
}

The first few lines of my CC tasks are pretty standard (I assume):

export async function run(event) { 
    let asset = DB.asset.create(); // allow autocomplete
    asset = event.object; 

Each Asset is connected to a parent Tenant.
Viewing the JSON, you can see the ps_tenant fields.
But HOW DO I ACCESS THEM in the CC Task.

CC seems to look for the element named “object” and does something special with it.
But all the data I need has been passed in via the event parm… I just can’t access it all.

Currently I have to do a database call to get field values in the “belongs to” related table - again, looking at the above JSON shows the entire “ps_tenant” structure should be available.

Hopefully some CC guru will have run across this before.

Thx
Jaymer…

1 Like