Skip to content

Commit

Permalink
Merge branch 'release/5.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
nsteenbeek committed Aug 23, 2021
2 parents 5e94b56 + 1e53eb7 commit fbd4284
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bin/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@hso/d365-cli",
"version": "5.3.2",
"version": "5.4.0",
"author": "HSO Innovation <[email protected]> (http://www.hso.com)",
"description": "HSO D365 Command Line Interface",
"repository": {
Expand Down
17 changes: 11 additions & 6 deletions src/generator/Enum.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export class Enum {
let savedQueriesString = '';
savedQueriesString += `export const ${this.entityName.charAt(0).toLowerCase()}${this.entityName.slice(1)}Views = {\n`;
const savedQueries = await SavedQueryService.retrieveMultipleRecords({
select: ['savedqueryid', 'name', 'returnedtypecode', 'savedqueryidunique'],
select: ['savedqueryid', 'name', 'returnedtypecode'],
filters: [{
conditions: [{
attribute: 'returnedtypecode',
Expand All @@ -52,10 +52,10 @@ export class Enum {
}, this.bearer);
for (const savedQuery of savedQueries) {
if (savedQuery && savedQuery.returnedtypecode === this.entityLogicalName) {
const {name, savedqueryidunique} = savedQuery;
const {name, savedqueryid} = savedQuery;
savedQueriesString += ` ${Enum.capitalize(name.replace(/ /g, ''))}: {\n`;
savedQueriesString += ` name: '${name}',\n`;
savedQueriesString += ` savedqueryidunique: '${savedqueryidunique}',\n`;
savedQueriesString += ` savedqueryid: '${savedqueryid}',\n`;
savedQueriesString += ` },\n`;
}
}
Expand Down Expand Up @@ -91,11 +91,16 @@ export class Enum {
let enumStrings = '';
const attributesMetadata = await NodeApi.getAttributesMetadata(this.entityLogicalName, this.bearer);
for (const attribute of attributesMetadata) {
const {AttributeType: attributeType, LogicalName: logicalName, SchemaName: schemaName} = attribute;
if (attributeType === 'Picklist') {
const {AttributeType: attributeType, LogicalName: logicalName, SchemaName: schemaName, AttributeTypeName: attributeTypeName} = attribute;
if (attributeType === 'Picklist' || attributeTypeName.Value === 'MultiSelectPicklistType') {
const pascalSchemaName = Enum.capitalize(schemaName);
enumStrings += `export enum ${pascalSchemaName} {\n`;
const options = await NodeApi.getPicklistOptionSet(this.entityLogicalName, logicalName, this.bearer);
let options;
if (attributeType === 'Picklist') {
options = await NodeApi.getPicklistOptionSet(this.entityLogicalName, logicalName, this.bearer);
} else {
options = await NodeApi.getMultiSelectPicklistAttributeMetadata(this.entityLogicalName, logicalName, this.bearer);
}
for (const option of options) {
let label = option.label.replace(/\W/g, '');
if (!label.charAt(0).match(/^[a-zA-Z]/)) {
Expand Down
4 changes: 3 additions & 1 deletion src/generator/Model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ export class Model {
// https://docs.microsoft.com/en-us/dotnet/api/microsoft.xrm.sdk.metadata.attributemetadata?view=dynamics-general-ce-9
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private async getInterfaceType(attribute: any): Promise<string> {
const {AttributeType: attributeType, SchemaName: schemaName} = attribute;
const {AttributeType: attributeType, SchemaName: schemaName, AttributeTypeName: attributeTypeName} = attribute;
if (['String', 'Memo', 'DateTime', 'Lookup', 'Customer', 'Owner', 'Uniqueidentifier'].includes(attributeType)) {
return 'string';
} else if (['Boolean'].includes(attributeType)) {
Expand All @@ -193,6 +193,8 @@ export class Model {
} else if (['State'].includes(attributeType)) {
const options = await NodeApi.getStateOptionSet(this.entityLogicalName, this.bearer);
return options.map(option => option.value).join(' | ');
} else if (attributeTypeName.Value === 'MultiSelectPicklistType') {
return 'number[]';
}
}

Expand Down
4 changes: 4 additions & 0 deletions src/root/tools/AttributeMetadata.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface AttributeMetadata {
LogicalName: string;
AttributeType: string;
SchemaName: string;
AttributeTypeName: {
Value: string;
}
}
17 changes: 17 additions & 0 deletions src/root/tools/NodeApi/NodeApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,23 @@ export class NodeApi {
});
}

public static async getMultiSelectPicklistAttributeMetadata(entityLogicalName: string, attribute: string, bearer: string): Promise<OptionSetOption[]> {
const {crm} = NodeApi.getSettings(),
{url, version} = crm,
// eslint-disable-next-line max-len
uri = `${url}/api/data/v${version}/EntityDefinitions(LogicalName='${entityLogicalName}')/Attributes(LogicalName='${attribute}')/Microsoft.Dynamics.CRM.MultiSelectPicklistAttributeMetadata?$select=LogicalName&$expand=OptionSet($select=Options)`,
{body} = await NodeApi.request('GET', uri, null, {
'Authorization': `Bearer ${bearer}`
});
return body.OptionSet.Options.map((option: {Value: number; ExternalValue: number; Label: {UserLocalizedLabel: {Label: string}}}) => {
return {
value: option.Value,
externalValue: option.ExternalValue,
label: option.Label.UserLocalizedLabel.Label
};
});
}

public static async getPicklistOptionSet(entityLogicalName: string, attribute: string, bearer: string): Promise<OptionSetOption[]> {
const {crm} = NodeApi.getSettings(),
{url, version} = crm,
Expand Down

0 comments on commit fbd4284

Please sign in to comment.