Skip to content

GenerateEntity

Niels Steenbeek edited this page Mar 20, 2020 · 13 revisions

CLI Command generate Entity [name]

Command

hso-d365 generate Entity [name]

Description

CLI Command 'generate Entity' generates an Entity.

Generated files

Following files will be generated:

  1. src/[name]/[name].form.ts
  2. src/[name]/[name].model.ts
  3. src/[name]/[name].service.ts
  4. src/[name]/[name].ts

Configuration

An entry will be added for you in webpack.config.js file.

[name].ts

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.

[name].form.ts

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});
        }
    }
}

[name].model.ts

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;
}

[name].service.ts

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.

Help

Use command

hso-d365 generate Entity --help
Clone this wiki locally