💼 Opportunity Implementation

Implementatie van de Core Library binnen de Opportunity-entiteit (sales pipeline en synchronisatie).

← Terug naar Core Library

📖 Introductie

De Opportunity-library verzorgt alle formulierlogica voor de sales pipeline binnen Dataverse. De implementatie maakt gebruik van de centrale onited.core library zodat de entity code compact en onderhoudbaar blijft.

👉 Opportunity = sales pipeline layer
👉 Core Library = herbruikbare logica

🏗️ Architectuur

De library volgt de standaard Onited structuur:

  1. Namespace initialisatie
  2. Helper functies
  3. OnLoad initialisatie
  4. Event binding
  5. Business logica
  6. Save validaties

🧩 Namespace

const onitedOpportunity = global.onitedOpportunity || {};
global.onitedOpportunity = onitedOpportunity;
          
👉 Voorkomt globale conflicten en ondersteunt hergebruik

🔌 Gebruik van Core Library

Event binding

onited.core.Field.addOnChangeSafe(
  formContext,
  "onited_status",
  onitedOpportunity.onChange_PipelineStage
);
          

Logging

onited.core.Logger.logError(
  "Error saving opportunity",
  e,
  formContext,
  uniqueId
);
          

Notifications

  • showFormNotification
  • showFieldNotification
  • clearAlerts

📊 Businesslogica

Opportunity type

  • Dynamisch tonen/verbergen van tabs
  • Gebruik van UI.showTab en UI.showSection

Pipeline → probability

const probability = pipelineStage % 1000;

onited.core.Field.setValue(
  formContext,
  "closeprobability",
  probability
);
          
👉 Automatische berekening voorkomt handmatige fouten

🔗 Salesbuildr synchronisatie

Account

  • retrieveRecord via Web API
  • Status validatie
  • Update indien nodig
await Xrm.WebApi.updateRecord(
  "account",
  accountId,
  account
);
          

Contact

  • Zelfde synchronisatie patroon
  • Zorgt voor consistente data

⏱️ Async patterns

await Promise.all([
  onitedOpportunity.accountSyncPromise,
  onitedOpportunity.contactSyncPromise
]);
          
👉 Voorkomt race conditions en verhoogt betrouwbaarheid

⛔ Disable scripting

  • onited_disablescripting
  • Skip business logica indien actief

📐 Standaardisatie

  • Zelfde pattern als Account / Contact / Lead
  • Consistente code structuur
  • Hogere herbruikbaarheid
⚠️ Houd alle entity scripts synchroon met de Core Library standaarden

🔗 Source code

👉 Bekijk de implementatie:
🔗 onited_opportunity.js