Skip to content

Commit da89cd0

Browse files
authored
New Components - microsoft_dynamics_365_sales (#15478)
* new components * pnpm-lock.yaml * version * improve summary * fix * filter solutionId prop
1 parent d4fe2e1 commit da89cd0

File tree

6 files changed

+762
-8
lines changed

6 files changed

+762
-8
lines changed
Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
import microsoft from "../../microsoft_dynamics_365_sales.app.mjs";
2+
import languageCodes from "../../common/language-codes.mjs";
3+
import pluralize from "pluralize";
4+
5+
export default {
6+
key: "microsoft_dynamics_365_sales-create-custom-entity",
7+
name: "Create Custom Entity",
8+
description: "Create a custom entity. [See the documentation](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/create-update-entity-definitions-using-web-api)",
9+
version: "0.0.1",
10+
type: "action",
11+
props: {
12+
microsoft,
13+
solutionId: {
14+
propDefinition: [
15+
microsoft,
16+
"solutionId",
17+
],
18+
},
19+
displayName: {
20+
type: "string",
21+
label: "Display Name",
22+
description: "The name of the new entity. E.g. `Bank Account`",
23+
},
24+
primaryAttribute: {
25+
type: "string",
26+
label: "Primary Attribute",
27+
description: "The primary name attribute of the new entity. E.g. `Account Name`",
28+
},
29+
languageCode: {
30+
type: "integer",
31+
label: "Language Code",
32+
description: "The language code to use for the entity",
33+
options: languageCodes,
34+
default: 1033,
35+
optional: true,
36+
},
37+
additionalAttributes: {
38+
type: "object",
39+
label: "Additional Attributes",
40+
description: "An array of objects representing attributes to add to the custom entity. [See the documentation](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/create-update-entity-definitions-using-web-api) for more information about formatting attribute objects",
41+
optional: true,
42+
},
43+
description: {
44+
type: "string",
45+
label: "Description",
46+
description: "A description of the new entity",
47+
optional: true,
48+
},
49+
hasActivities: {
50+
type: "boolean",
51+
label: "Has Activities",
52+
description: "Set to `true` if the new entity has activities",
53+
default: false,
54+
optional: true,
55+
},
56+
hasNotes: {
57+
type: "boolean",
58+
label: "Has Notes",
59+
description: "Set to `true` if the new entity has notes",
60+
default: false,
61+
optional: true,
62+
},
63+
},
64+
methods: {
65+
parseAttributes() {
66+
return this.additionalAttributes
67+
? typeof this.additionalAttributes === "string"
68+
? JSON.parse(this.additionalAttributes)
69+
: this.additionalAttributes
70+
: [];
71+
},
72+
removeSpaces(str) {
73+
return str.replace(/\s+/g, "");
74+
},
75+
buildLocalizedLabelArray(label) {
76+
return [
77+
{
78+
"@odata.type": "Microsoft.Dynamics.CRM.LocalizedLabel",
79+
"Label": label,
80+
"LanguageCode": this.languageCode,
81+
},
82+
];
83+
},
84+
},
85+
async run({ $ }) {
86+
const solution = await this.microsoft.getSolution({
87+
$,
88+
solutionId: this.solutionId,
89+
});
90+
91+
const { customizationprefix } = await this.microsoft.getPublisher({
92+
$,
93+
publisherId: solution._publisherid_value,
94+
});
95+
96+
const attributes = this.parseAttributes();
97+
98+
const { headers } = await this.microsoft.createCustomEntity({
99+
$,
100+
returnFullResponse: true,
101+
headers: {
102+
"MSCRM.SolutionUniqueName": solution.uniquename,
103+
},
104+
data: {
105+
"@odata.type": "Microsoft.Dynamics.CRM.EntityMetadata",
106+
"Attributes": [
107+
{
108+
"@odata.type": "Microsoft.Dynamics.CRM.StringAttributeMetadata",
109+
"DisplayName": {
110+
"@odata.type": "Microsoft.Dynamics.CRM.Label",
111+
"LocalizedLabels": this.buildLocalizedLabelArray(this.primaryAttribute),
112+
},
113+
"IsPrimaryName": true,
114+
"SchemaName": `${customizationprefix}_${this.removeSpaces(this.primaryAttribute)}`,
115+
"MaxLength": 100,
116+
"FormatName": {
117+
"Value": "Text",
118+
},
119+
"RequiredLevel": {
120+
"Value": "None",
121+
"CanBeChanged": true,
122+
"ManagedPropertyLogicalName": "canmodifyrequirementlevelsettings",
123+
},
124+
},
125+
...attributes,
126+
],
127+
"DisplayName": {
128+
"@odata.type": "Microsoft.Dynamics.CRM.Label",
129+
"LocalizedLabels": this.buildLocalizedLabelArray(this.displayName),
130+
},
131+
"DisplayCollectionName": {
132+
"@odata.type": "Microsoft.Dynamics.CRM.Label",
133+
"LocalizedLabels": this.buildLocalizedLabelArray(pluralize(this.displayName)),
134+
},
135+
"Description": this.description && {
136+
"@odata.type": "Microsoft.Dynamics.CRM.Label",
137+
"LocalizedLabels": this.buildLocalizedLabelArray(this.description),
138+
},
139+
"HasActivities": this.hasActivities,
140+
"HasNotes": this.hasNotes,
141+
"SchemaName": `${customizationprefix}_${this.removeSpaces(this.displayName)}`,
142+
"PrimaryNameAttribute": `${customizationprefix}_${this.removeSpaces(this.primaryAttribute)}`,
143+
"OwnershipType": "UserOwned",
144+
},
145+
});
146+
147+
const entityId = headers["odata-entityid"].substring(headers["odata-entityid"].lastIndexOf("/") + 1);
148+
const response = await this.microsoft.getEntity({
149+
$,
150+
entityId,
151+
});
152+
153+
$.export("$summary", `Successfully created custom entity with ID: ${entityId}`);
154+
155+
return response;
156+
},
157+
};
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import microsoft from "../../microsoft_dynamics_365_sales.app.mjs";
2+
3+
export default {
4+
key: "microsoft_dynamics_365_sales-find-contact",
5+
name: "Find Contact",
6+
description: "Search for a contact by id, name, or using a custom filter. [See the documentation](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/query/overview)",
7+
version: "0.0.1",
8+
type: "action",
9+
props: {
10+
microsoft,
11+
contactId: {
12+
propDefinition: [
13+
microsoft,
14+
"contactId",
15+
],
16+
},
17+
name: {
18+
type: "string",
19+
label: "Name",
20+
description: "Find contacts whose full name contains the name entered",
21+
optional: true,
22+
},
23+
filter: {
24+
type: "string",
25+
label: "Filter",
26+
description: "Enter a custom filter to search contacts. E.g. `lastname eq 'Smith'`. [See the documentation] for more information about [filters](https://learn.microsoft.com/en-us/power-apps/developer/data-platform/webapi/query/filter-rows)",
27+
optional: true,
28+
},
29+
},
30+
async run({ $ }) {
31+
const filterArray = [];
32+
if (this.contactId) {
33+
filterArray.push(`contactid eq '${this.contactId}'`);
34+
}
35+
if (this.name) {
36+
filterArray.push(`contains(fullname, '${this.name}')`);
37+
}
38+
if (this.filter) {
39+
filterArray.push(`(${this.filter})`);
40+
}
41+
42+
const filter = filterArray.length
43+
? filterArray.join(" and ")
44+
: undefined;
45+
46+
const { value } = await this.microsoft.listContacts({
47+
$,
48+
params: {
49+
$filter: filter,
50+
},
51+
});
52+
53+
$.export("$summary", `Successfully retrieved ${value.length} contact${value.length === 1
54+
? ""
55+
: "s"}`);
56+
57+
return value;
58+
},
59+
};

0 commit comments

Comments
 (0)