# Phase 1 & 2 — Environment provisioning and app installation

## 1. Authenticate

```powershell
pac auth create --name caldova
pac admin list-app-templates      # shows which D365 app templates the tenant licences
```

`pac auth create` opens a browser. Sign in as the tenant admin
(`admin@caldova<nnnnnnnn>.onmicrosoft.com`).

### Watch out: `pac admin list` hides environments

It only lists environments **that have a Dataverse database**. The pre-existing
"Caldova (default)" environment is invisible to it. Do not conclude the tenant is empty.

### Watch out: PPAC defaults to the wrong tenant

If you are a Microsoft employee, the Power Platform admin center will silently open in your
**corporate** tenant and show corporate environments. Always check the account avatar before
acting.

Get the Caldova tenant ID from the public discovery endpoint:

```powershell
curl "https://login.microsoftonline.com/caldova<nnnnnnnn>.onmicrosoft.com/v2.0/.well-known/openid-configuration" |
  ConvertFrom-Json | Select-Object -ExpandProperty issuer
```

Then force PPAC to that tenant.

---

## 2. Check licensing before assuming anything is missing

The Caldova tenant licenses CE through a single bundle SKU:

**"Dynamics 365 and Power Platform multi-app demo"**

Its service plans include Dynamics 365 for **Sales**, **Customer Service**, **Field Service**,
**Project Operations CDS**, **Relationship Sales** and **Marketing**. There is no standalone
Sales or Customer Service SKU — do not go looking for one and conclude you are unlicensed.

Verify in **M365 admin center → Billing → Licenses → [SKU] → service plans**, and confirm the
plans are *enabled* on the admin account.

> The CDX experience page "Products" list is **marketing copy, not a licence manifest**.
> It omitted Sales and Customer Service even though both were fully licensed. Ignore it.

---

## 3. Create the environment — use the PPAC wizard, not the CLI

### Why not the CLI

`pac admin create --templates "D365_Sales,D365_CustomerService"` returns success but does not
reliably set the **"Enable Dynamics 365 apps"** flag. That flag:

- defaults to **No**
- is explicitly labelled **irreversible**
- cannot be turned on later

If it is off, app installs appear to succeed and nothing ever deploys.

### The wizard path

**PPAC → Environments → New**, then:

1. Name, Region, Type = **Sandbox** (convert to Production later — see phase 5)
2. **Change default settings**
3. **Add a Dataverse data store: Yes** → Next
4. **Enable Dynamics 365 apps: Yes** ← the critical toggle
5. **Automatically deploy these apps** — multi-select
6. Security group: **None** for open demo access
7. Save

Provisioning takes ~1 minute.

### Solo-only apps — these each need their own dedicated environment

These **cannot** be deployed alongside other apps. The wizard errors with
*"The CDS app 'X' cannot be provisioned with other apps."*

- Contact Center
- Microsoft 365 Copilot – Service Solution
- Guides
- Remote Assist

Remove them from the multi-select and deploy them separately if you need them.

**Only Sales Enterprise + Customer Service co-deploy cleanly at creation time.**
Field Service is greyed out in the creation dropdown but **installs fine post-hoc**.

### DOM note for automation

The app checkboxes are `templates-list{N}`. The `<input>` is intercepted, so click the
`label[for=...]` instead. Multi-select options live in a portal/shadow root —
`document.querySelectorAll('[role="option"]')` returns nothing; DOM-walk from text nodes
or use element IDs.

---

## 4. Install the app portfolio

```powershell
pac org select --environment "https://<org>.crm.dynamics.com/"
pac application list --environment <envid>          # catalog (see caveat below)
pac application install --application-name msdyn_SalesPremiumDemoAnchor
```

### Install strategy

- **Install apps one at a time.** Batch mode (`--application-list`) **serialises** — one stuck
  package blocks everything behind it.
- **Expect 5–60 minutes each.** The CLI often never returns even after success.
- **Verify in the org UI**, not the CLI: `/main.aspx?forceUCI=1&pagetype=apps`
- If the CLI hangs past 60 min, kill it and check the org UI. It has very likely landed.

### Useful anchors

| App | Anchor |
|---|---|
| Sales Premium demo | `msdyn_SalesPremiumDemoAnchor` |
| Customer Service demo data | `msdyn_CustomerServiceDemoDataAnchor` |
| Customer Service demo hub | `msdyn_CustomerServiceDemoHubAnchor` |
| Sales Agent Digital Worker | `msdyn_DigitalWorkerAnchor` |

### Known flaky install

`msdyn_CustomerServiceDemoHubAnchor` failed with
`Failed to install application within maximum timeout of 60 minutes`.
Installing **Customer Service Demo Data alone** succeeded in ~20 min. If the Hub fails, check
the org UI before retrying — it may have landed anyway.

### Observed timings

| App | Time to land |
|---|---|
| Sales Premium Demo | ~5.5 min |
| Customer Service Demo Data | ~20 min |
| Project Operations | ~35 min |
| Field Service | ~50+ min |

---

## 5. Verify

Open `https://<org>.crm.dynamics.com/main.aspx?forceUCI=1&pagetype=apps` and count the tiles.

A complete build shows roughly **18-22 published apps** depending on optional packages. If you see 3 solutions in `pac solution list`
and panic — don't. That command is broken. Look at the org UI.

Next: `02-connections-and-agents.md` — and do not skip it.

