-
Notifications
You must be signed in to change notification settings - Fork 1
GenerateEntity
Niels Steenbeek edited this page Mar 20, 2020
·
13 revisions
hso-d365 generate Entity [name]
CLI Command 'generate Entity' generates an Entity.
Following files will be generated:
- src/[name]/[name].form.ts
- src/[name]/[name].model.ts
- src/[name]/[name].service.ts
- src/[name]/[name].ts
An entry will be added for you in webpack.config.js file.
This is the root file. It mentions the function you have to add to your D365 form or ribbon:
- onLoad function for your form (take care to check the 'pass formcontext' checkbox)
- myRibbonMethod for your ribbon Normally you don't touch this file that much.
This is the file for form logic. The onLoad is the starting point for all your business logic.
import {Translation} from '../translation/Translation';
import {AccountService} from './Account.service';
import {AccountModel} from './Account.model';
export class AccountForm {
static async onLoad(executionContext: Xrm.Events.EventContext): Promise<void> {
const accounts: AccountModel[] = await AccountService.retrieveMultipleRecords({
select: ['name', 'description'],
filters: [{
type: 'and',
conditions: [{
attribute: 'name',
operator: 'eq',
value: 'test'
}]
}]
});
for (const account of accounts) {
console.log(`${account.name} has description ${account.description});
}
}
}
This file contains all fields/NavigationPropertyNames for the odata query. The [name].service.ts class needs it.
export interface AccountModel extends Model {
name?: string;
description?: string;
}
This file wraps the Xrm.WebApi methods and also knows the logicalName. Normally you use the Service class in your Form class instead of using the WebApi class directly. See more about WebApi. Here you can add [name] Entity specific API calls and actions.
Use command
hso-d365 generate Entity --help