-
Notifications
You must be signed in to change notification settings - Fork 16
Home
Scott Durow edited this page Apr 22, 2020
·
5 revisions
_ _ __ __
___ __| |___(_)/ _|_ _ \ \
/ __/ _` / __| | |_| | | | \ \
| (_| (_| \__ \ | _| |_| | / /
\___\__,_|___/_|_| \__, | /_/
|___/
The TypeScript library that allows you to use the CDS/Xrm WebApi using IOrganizationService SDK like types. Works with cdsify-gen and node-cds-auth to create early bound classes.
- Implement an API for use from TypeScript that is close to IOrganizationService for use in Model-Driven Form JS Web-Resources or PCF controls.
- Cross-Platform - pure NodeJS - runs inside VSCode on Windows/Mac/Linux
- Early bound generation of Entities/Actions/Functions with customizable templates.
- Be as unopinionated as possible - but still promote TypeScript best practices.
- Allow integration testing from inside VSCode/NodeJS tests.
- Works right from inside VSCode
- Provides similar syntax similar to the server-side CDS/XRM SDK (e.g. IOrganizationService create, update, delete, retrieve, retreiveMultiple, execute)
- Deals with some of the limitations of the WebApi (e.g. not being able to null lookup fields).
- Deals with the complexity of calling actions/functions via the WebApi.
- The API is delivered as node modules that can be webpacked into your own libraries rather than loaded as externals.
- Runs purely on nodejs and works cross-platform.
- Delivered via npm - not NuGet - and so only needs VSCode.
- Uses On-behalf-of authentication flow - no username/password/appid needed (this is also cross-platform using
node-cds-auth
). - Provides an implementation of Xrm.WebApi.* that can be used in NodeJS integration tests without running in the CDS browser context.
- Provides customisable ejs templates via
cdsify-gen eject
- Provides a CLI for easily adding types/actions/functions to your project
- Doesn't attempt to provide form script typings - rather simple attribute name constants can be used. You could still use XrmDefinitelyTyped for this if you wish.
This is how you would create an account, opportunity, then win the opportunity in TypeScript running in the Form Context:
// Create account
const account1 = {
logicalName: accountMetadata.logicalName,
name: "Account 1",
} as Account;
account1.id = await cdsServiceClient.create(account1);
// Create opportunity
const opportunity1 = {
logicalName: opportunityMetadata.logicalName,
name: "Opportunity 1",
} as Opportunity;
opportunity1.customerid = Entity.toEntityReference(account1);
opportunity1.id = await cdsServiceClient.create(opportunity1);
// WinOpportunity
const winRequest = {
logicalName: WinOpportunityMetadata.operationName,
Status: 3,
OpportunityClose: {
logicalName: opportunitycloseMetadata.logicalName,
description: "Sample Opportunity Close",
subject: "Sample",
opportunityid: Entity.toEntityReference(opportunity1),
},
} as WinOpportunityRequest;
const winResponse = await cdsServiceClient.execute(winRequest);
// Get the Opportunity
const opportunityRetreived = (await cdsServiceClient.retrieve(opportunity1.logicalName, opportunity1.id,
"customerid",
])) as Opportunity;
console.log(opportunityRetreived.customerid?.id);
You can also use activity parties for creating activities:
letter1.regardingobjectid = Entity.toEntityReference(account1);
letter1.to = [
{
logicalName: "activityparty",
partyid: Entity.toEntityReference(account1)
} as ActivityParty
];
letter1.id = await cdsServiceClient.create(letter1);
More information - Quick-Start