@tekstack/client-data-model 1.0.0 → 1.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/README.md +2 -0
  2. package/out/commonFunctions/TekStackSettings.d.ts +30 -0
  3. package/out/commonFunctions/TekStackSettings.d.ts.map +1 -0
  4. package/out/commonFunctions/TekStackSettings.js +161 -0
  5. package/out/commonFunctions/TekStackSettings.js.map +1 -0
  6. package/out/commonFunctions/Utilities.d.ts +93 -0
  7. package/out/commonFunctions/Utilities.d.ts.map +1 -0
  8. package/out/commonFunctions/Utilities.js +351 -0
  9. package/out/commonFunctions/Utilities.js.map +1 -0
  10. package/out/commonFunctions/index.d.ts +3 -0
  11. package/out/commonFunctions/index.d.ts.map +1 -0
  12. package/out/commonFunctions/index.js +19 -0
  13. package/out/commonFunctions/index.js.map +1 -0
  14. package/out/constants/constants.d.ts +3 -0
  15. package/out/constants/constants.d.ts.map +1 -0
  16. package/out/constants/constants.js +6 -0
  17. package/out/constants/constants.js.map +1 -0
  18. package/out/constants/createFormConstants.d.ts +4 -0
  19. package/out/constants/createFormConstants.d.ts.map +1 -0
  20. package/out/constants/createFormConstants.js +7 -0
  21. package/out/constants/createFormConstants.js.map +1 -0
  22. package/out/constants/formIds.d.ts +112 -0
  23. package/out/constants/formIds.d.ts.map +1 -0
  24. package/out/constants/formIds.js +120 -0
  25. package/out/constants/formIds.js.map +1 -0
  26. package/out/constants/index.d.ts +5 -0
  27. package/out/constants/index.d.ts.map +1 -0
  28. package/out/constants/index.js +21 -0
  29. package/out/constants/index.js.map +1 -0
  30. package/out/constants/securityRoleIds.d.ts +15 -0
  31. package/out/constants/securityRoleIds.d.ts.map +1 -0
  32. package/out/constants/securityRoleIds.js +18 -0
  33. package/out/constants/securityRoleIds.js.map +1 -0
  34. package/out/customApis/index.d.ts +25 -0
  35. package/out/customApis/index.d.ts.map +1 -0
  36. package/out/customApis/index.js +41 -0
  37. package/out/customApis/index.js.map +1 -0
  38. package/out/entities/tekstack_Token.d.ts +97 -0
  39. package/out/entities/tekstack_Token.d.ts.map +1 -0
  40. package/out/entities/tekstack_Token.js +35 -0
  41. package/out/entities/tekstack_Token.js.map +1 -0
  42. package/out/enums/tekstack_token_tekstack_token_statecode.d.ts +5 -0
  43. package/out/enums/tekstack_token_tekstack_token_statecode.d.ts.map +1 -0
  44. package/out/enums/tekstack_token_tekstack_token_statecode.js +3 -0
  45. package/out/enums/tekstack_token_tekstack_token_statecode.js.map +1 -0
  46. package/out/enums/tekstack_token_tekstack_token_statuscode.d.ts +5 -0
  47. package/out/enums/tekstack_token_tekstack_token_statuscode.d.ts.map +1 -0
  48. package/out/enums/tekstack_token_tekstack_token_statuscode.js +3 -0
  49. package/out/enums/tekstack_token_tekstack_token_statuscode.js.map +1 -0
  50. package/out/index.d.ts +7 -1
  51. package/out/index.d.ts.map +1 -1
  52. package/out/index.js +7 -3
  53. package/out/index.js.map +1 -1
  54. package/out/metadata.d.ts +29 -145
  55. package/out/metadata.d.ts.map +1 -1
  56. package/out/metadata.js +5 -6
  57. package/out/metadata.js.map +1 -1
  58. package/package.json +1 -1
package/README.md CHANGED
@@ -15,6 +15,8 @@ From this folder:
15
15
  npm install
16
16
  npm run build
17
17
  npm pack
18
+ npm login
19
+ npm publish --access public
18
20
  ```
19
21
 
20
22
  `npm run build` will:
@@ -0,0 +1,30 @@
1
+ export interface IQuickBooksSettings {
2
+ tekstack_QuickBooksBaseAPI: string;
3
+ tekstack_QuickBooksClientId: string;
4
+ tekstack_QuickBooksCompanyId: string;
5
+ }
6
+ export declare class TekStackSettings {
7
+ /**
8
+ * Returns the values of the tekstack_usebdrteam field in TekStack Settings and saves it in session storage so we don't have to keep calling the API.
9
+ */
10
+ static useBDRTeam(): Promise<Boolean>;
11
+ /**
12
+ * Returns the values of the tekstack_createteamschannels field in TekStack Settings and saves it in session storage so we don't have to keep calling the API.
13
+ */
14
+ static createTeamsChannels(): Promise<Boolean>;
15
+ /**
16
+ * Returns the values of the tekstack_AccountEditFormId settings and saves it in session storage so we don't have to keep calling the API.
17
+ */
18
+ static AccountEditFormId(): Promise<string>;
19
+ /**
20
+ * Returns the values of the tekstack_categorizetimeentry field in TekStack Settings and saves it in session storage so we don't have to keep calling the API.
21
+ */
22
+ static showTimeCategories(): Promise<Boolean>;
23
+ /**
24
+ * Gets the QuickBooks settings from the tekstack_tekstackconfigurations table and saves it in session storage so we don't have to keep calling the API. If there is an error parsing the settings from session storage, it will clear the session storage and retrieve the settings again.
25
+ * This is necessary because the client ID and secret are stored in an encoded format, and if there is an error parsing the settings, it could be due to a change in the encoding format or an issue with the stored value. By clearing the session storage and retrieving the settings again, we can ensure that we have the correct values.
26
+ * @returns
27
+ */
28
+ static quickBooksSettings(): Promise<IQuickBooksSettings | null>;
29
+ }
30
+ //# sourceMappingURL=TekStackSettings.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TekStackSettings.d.ts","sourceRoot":"","sources":["../../src/commonFunctions/TekStackSettings.ts"],"names":[],"mappings":"AAQA,MAAM,WAAW,mBAAmB;IAClC,0BAA0B,EAAE,MAAM,CAAC;IACnC,2BAA2B,EAAE,MAAM,CAAC;IACpC,4BAA4B,EAAE,MAAM,CAAC;CACtC;AAGD,qBAAa,gBAAgB;IAE3B;;OAEG;WACU,UAAU,IAAI,OAAO,CAAC,OAAO,CAAC;IAgC3C;;OAEG;WACU,mBAAmB,IAAI,OAAO,CAAC,OAAO,CAAC;IA6BpD;;OAEG;WACU,iBAAiB,IAAI,OAAO,CAAC,MAAM,CAAC;IAYjD;;OAEG;WACU,kBAAkB,IAAI,OAAO,CAAC,OAAO,CAAC;IA6BnD;;;;OAIG;WACU,kBAAkB,IAAI,OAAO,CAAC,mBAAmB,GAAC,IAAI,CAAC;CA6CrE"}
@@ -0,0 +1,161 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.TekStackSettings = void 0;
4
+ const dataverse_ify_1 = require("dataverse-ify");
5
+ const __1 = require("../");
6
+ const tekstack_AccountEditFormId = "tekstack_AccountEditFormId";
7
+ class TekStackSettings {
8
+ /**
9
+ * Returns the values of the tekstack_usebdrteam field in TekStack Settings and saves it in session storage so we don't have to keep calling the API.
10
+ */
11
+ static async useBDRTeam() {
12
+ if (!sessionStorage.getItem("tekstack_usebdrteam" /* tcA.tekstack_usebdrteam */)) {
13
+ const query = `?$select=${"tekstack_usebdrteam" /* tcA.tekstack_usebdrteam */}`;
14
+ // we need to call this method first
15
+ (0, dataverse_ify_1.setMetadataCache)(__1.metadataCache);
16
+ const dataverseClient = new dataverse_ify_1.XrmContextDataverseClient(Xrm.WebApi);
17
+ // UPDATE THIS TO RETRIEVE THE PARENT TABLE AND FIELDS, THEN SET THE FIELDS ON THIS TABLE
18
+ const settings = await dataverseClient.retrieveMultiple(query, { logicalName: __1.tekstack_tekstackconfigurationsMetadata.logicalName });
19
+ if (settings.entities.length === 1
20
+ && settings.entities[0]["tekstack_usebdrteam" /* tcA.tekstack_usebdrteam */] === true) {
21
+ sessionStorage.setItem("tekstack_usebdrteam" /* tcA.tekstack_usebdrteam */, "true");
22
+ return true;
23
+ }
24
+ else {
25
+ sessionStorage.setItem("tekstack_usebdrteam" /* tcA.tekstack_usebdrteam */, "false");
26
+ return false;
27
+ }
28
+ }
29
+ else {
30
+ // use the value from session storage
31
+ if (sessionStorage.getItem("tekstack_usebdrteam" /* tcA.tekstack_usebdrteam */) === "true") {
32
+ return true;
33
+ }
34
+ else {
35
+ return false;
36
+ }
37
+ }
38
+ }
39
+ /**
40
+ * Returns the values of the tekstack_createteamschannels field in TekStack Settings and saves it in session storage so we don't have to keep calling the API.
41
+ */
42
+ static async createTeamsChannels() {
43
+ if (!sessionStorage.getItem("tekstack_createteamschannels" /* tcA.tekstack_createteamschannels */)) {
44
+ const query = `?$select=${"tekstack_createteamschannels" /* tcA.tekstack_createteamschannels */}`;
45
+ // we need to call this method first
46
+ (0, dataverse_ify_1.setMetadataCache)(__1.metadataCache);
47
+ const dataverseClient = new dataverse_ify_1.XrmContextDataverseClient(Xrm.WebApi);
48
+ const settings = await dataverseClient.retrieveMultiple(query, { logicalName: __1.tekstack_tekstackconfigurationsMetadata.logicalName });
49
+ if (settings.entities.length === 1
50
+ && settings.entities[0]["tekstack_createteamschannels" /* tcA.tekstack_createteamschannels */] === true) {
51
+ sessionStorage.setItem("tekstack_createteamschannels" /* tcA.tekstack_createteamschannels */, "true");
52
+ return true;
53
+ }
54
+ else {
55
+ sessionStorage.setItem("tekstack_createteamschannels" /* tcA.tekstack_createteamschannels */, "false");
56
+ return false;
57
+ }
58
+ }
59
+ else {
60
+ // use the value from session storage
61
+ if (sessionStorage.getItem("tekstack_createteamschannels" /* tcA.tekstack_createteamschannels */) === "true") {
62
+ return true;
63
+ }
64
+ else {
65
+ return false;
66
+ }
67
+ }
68
+ }
69
+ /**
70
+ * Returns the values of the tekstack_AccountEditFormId settings and saves it in session storage so we don't have to keep calling the API.
71
+ */
72
+ static async AccountEditFormId() {
73
+ var _a, _b;
74
+ if (!sessionStorage.getItem(tekstack_AccountEditFormId)) {
75
+ const accountEditFormId = Xrm.Utility.getGlobalContext().getCurrentAppSetting(tekstack_AccountEditFormId).toString();
76
+ sessionStorage.setItem(tekstack_AccountEditFormId, accountEditFormId);
77
+ return accountEditFormId;
78
+ }
79
+ else {
80
+ // use the value from session storage
81
+ return (_b = (_a = sessionStorage.getItem(tekstack_AccountEditFormId)) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : "";
82
+ }
83
+ }
84
+ /**
85
+ * Returns the values of the tekstack_categorizetimeentry field in TekStack Settings and saves it in session storage so we don't have to keep calling the API.
86
+ */
87
+ static async showTimeCategories() {
88
+ if (!sessionStorage.getItem("tekstack_categorizetimeentry" /* tcA.tekstack_categorizetimeentry */)) {
89
+ const query = `?$select=${"tekstack_categorizetimeentry" /* tcA.tekstack_categorizetimeentry */}`;
90
+ // we need to call this method first
91
+ (0, dataverse_ify_1.setMetadataCache)(__1.metadataCache);
92
+ const dataverseClient = new dataverse_ify_1.XrmContextDataverseClient(Xrm.WebApi);
93
+ const settings = await dataverseClient.retrieveMultiple(query, { logicalName: __1.tekstack_tekstackconfigurationsMetadata.logicalName });
94
+ if (settings.entities.length === 1
95
+ && settings.entities[0]["tekstack_categorizetimeentry" /* tcA.tekstack_categorizetimeentry */] === true) {
96
+ sessionStorage.setItem("tekstack_categorizetimeentry" /* tcA.tekstack_categorizetimeentry */, "true");
97
+ return true;
98
+ }
99
+ else {
100
+ sessionStorage.setItem("tekstack_categorizetimeentry" /* tcA.tekstack_categorizetimeentry */, "false");
101
+ return false;
102
+ }
103
+ }
104
+ else {
105
+ // use the value from session storage
106
+ if (sessionStorage.getItem("tekstack_categorizetimeentry" /* tcA.tekstack_categorizetimeentry */) === "true") {
107
+ return true;
108
+ }
109
+ else {
110
+ return false;
111
+ }
112
+ }
113
+ }
114
+ /**
115
+ * Gets the QuickBooks settings from the tekstack_tekstackconfigurations table and saves it in session storage so we don't have to keep calling the API. If there is an error parsing the settings from session storage, it will clear the session storage and retrieve the settings again.
116
+ * This is necessary because the client ID and secret are stored in an encoded format, and if there is an error parsing the settings, it could be due to a change in the encoding format or an issue with the stored value. By clearing the session storage and retrieving the settings again, we can ensure that we have the correct values.
117
+ * @returns
118
+ */
119
+ static async quickBooksSettings() {
120
+ var _a;
121
+ if (sessionStorage.getItem("QuickBooksSettings")) {
122
+ try {
123
+ JSON.parse((_a = sessionStorage.getItem("QuickBooksSettings")) !== null && _a !== void 0 ? _a : "");
124
+ }
125
+ catch (e) {
126
+ // if there was an error parsing the settings, clear the session storage and retrieve the settings again
127
+ sessionStorage.removeItem("QuickBooksSettings");
128
+ return await this.quickBooksSettings();
129
+ }
130
+ }
131
+ const query = `?$select=${"tekstack_quickbooksbaseapi" /* tcA.tekstack_QuickBooksBaseAPI */},${"tekstack_quickbooksclientid" /* tcA.tekstack_QuickBooksClientId */},${"tekstack_quickbookscompanyid" /* tcA.tekstack_QuickBooksCompanyId */},${"tekstack_quickbookssecret" /* tcA.tekstack_QuickBooksSecret */}`;
132
+ // we need to call this method first
133
+ (0, dataverse_ify_1.setMetadataCache)(__1.metadataCache);
134
+ const dataverseClient = new dataverse_ify_1.XrmContextDataverseClient(Xrm.WebApi);
135
+ const settings = await dataverseClient.retrieveMultiple(query, { logicalName: __1.tekstack_tekstackconfigurationsMetadata.logicalName });
136
+ if (settings.entities.length === 1) {
137
+ const baseAPI = settings.entities[0]["tekstack_quickbooksbaseapi" /* tcA.tekstack_QuickBooksBaseAPI */];
138
+ const clientId = settings.entities[0]["tekstack_quickbooksclientid" /* tcA.tekstack_QuickBooksClientId */];
139
+ const secret = settings.entities[0]["tekstack_quickbookssecret" /* tcA.tekstack_QuickBooksSecret */];
140
+ const companyId = settings.entities[0]["tekstack_quickbookscompanyid" /* tcA.tekstack_QuickBooksCompanyId */];
141
+ if (baseAPI && clientId && companyId && secret) {
142
+ const bytes = new TextEncoder().encode(clientId + ":" + secret);
143
+ let binary = "";
144
+ for (const b of bytes)
145
+ binary += String.fromCharCode(b);
146
+ const encoded = btoa(binary);
147
+ const settings = {
148
+ tekstack_QuickBooksBaseAPI: baseAPI,
149
+ tekstack_QuickBooksClientId: encoded,
150
+ tekstack_QuickBooksCompanyId: companyId
151
+ };
152
+ const settingsString = JSON.stringify(settings);
153
+ sessionStorage.setItem("QuickBooksSettings", settingsString);
154
+ return settings;
155
+ }
156
+ }
157
+ return null;
158
+ }
159
+ }
160
+ exports.TekStackSettings = TekStackSettings;
161
+ //# sourceMappingURL=TekStackSettings.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TekStackSettings.js","sourceRoot":"","sources":["../../src/commonFunctions/TekStackSettings.ts"],"names":[],"mappings":";;;AAAA,iDAA8F;AAC9F,2BAKa;AAQb,MAAM,0BAA0B,GAAG,4BAA4B,CAAC;AAChE,MAAa,gBAAgB;IAE3B;;OAEG;IACH,MAAM,CAAC,KAAK,CAAC,UA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4BAA4B,EAAE,SAAS;iBACxC,CAAC;gBACF,MAAM,cAAc,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,CAAC;gBAChD,cAAc,CAAC,OAAO,CAAC,oBAAoB,EAAE,cAAc,CAAC,CAAC;gBAC7D,OAAO,QAAQ,CAAC;YAClB,CAAC;QACH,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;CACF;AAtKD,4CAsKC"}
@@ -0,0 +1,93 @@
1
+ export declare class Utilities {
2
+ /**
3
+ * Hides the form selector and the form header
4
+ * @param formContext
5
+ */
6
+ static hideFormSelector(formContext: Xrm.FormContext): void;
7
+ /**
8
+ * Hides the form selector but show the form header
9
+ * @param formContext
10
+ */
11
+ static hideFormSelectorShowHeader(formContext: Xrm.FormContext): void;
12
+ /**
13
+ * Shows the form selector
14
+ * @param formContext
15
+ */
16
+ static showFormSelector(formContext: Xrm.FormContext): void;
17
+ /**
18
+ * Initializes the create form by hiding the header section and tab navigator.
19
+ */
20
+ static initializeCreateForm(formContext: Xrm.FormContext): Promise<void>;
21
+ /**
22
+ * The guid id of the current form with no braces
23
+ * @param formContext
24
+ * @returns
25
+ */
26
+ static formId(formContext: Xrm.FormContext): string;
27
+ static openEditForm(eventContext: Xrm.Events.EventContext, savemode: number, formType: number, widthEditForm: number, guidEditForm: string, idrecord: string, recordentity: string, recordname: string, parentField: string): void;
28
+ static openEditForm2(eventContext: Xrm.Events.EventContext, savemode: number, formType: number, guidEditForm: string): void;
29
+ static toLookup(reference: import("dataverse-ify").EntityReference | undefined): Xrm.LookupValue[] | null;
30
+ static openAlertDialog(title: string, text: string, confirmButtonLabel: string, height: number, width: number): Promise<void>;
31
+ static retrieveEntity(entityLogicalName: string, id: string, columns: string): Promise<any>;
32
+ static convertToOdataField(field: string): string;
33
+ static convertToOdataName(field: string): string;
34
+ /**
35
+ * Returns the id of the current item with no braces
36
+ * @param formContext
37
+ * @returns
38
+ */
39
+ static myId(formContext: Xrm.FormContext): string;
40
+ /**
41
+ * Returns the id of the lookup field with no braces or null if not set
42
+ * @param lookupName the name of the lookup field
43
+ * @param formContext the form context
44
+ * @returns the id of the lookup field with no braces or null if not set
45
+ */
46
+ static getId(lookupName: string, formContext: Xrm.FormContext): string | null;
47
+ /**
48
+ * Returns the name of the lookup field or null if not set
49
+ * @param lookupName the name of the lookup field
50
+ * @param formContext the form context
51
+ * @returns the name of the lookup field or null if not set
52
+ */
53
+ static getName(lookupName: string, formContext: Xrm.FormContext): string | null;
54
+ /**
55
+ * Returns the parent using the id_record and record_entity fields passed in form parameters
56
+ * @param formContext the form context
57
+ * @returns a lookup to the parent record or null if the parameters are not set
58
+ */
59
+ static getParent(formContext: Xrm.FormContext): Xrm.LookupValue[] | null;
60
+ static stripBraces(idWithBraces: string): string;
61
+ /**
62
+ *
63
+ * @returns the current user's id with no braces
64
+ */
65
+ static myUserId(): string;
66
+ /**
67
+ * Returns the values of the useBDRTeam field in TekStack Settings and saves it in session storage so we don't have to keep calling the API.
68
+ * If the form is the specified type and this is the initial load, closes the form and opens the specified form.
69
+ * Used to redirect to the create form from the edit form and vice versa, if we are not in the matching mode.
70
+ * @param eventContext
71
+ * @param type
72
+ * @param formId
73
+ */
74
+ static redirectIfFormType(eventContext: Xrm.Events.EventContext, type: XrmEnum.FormType, formId: string): Promise<void>;
75
+ /**
76
+ * Returns the load type of the form. Only available in the form load event.
77
+ * @param eventContext
78
+ * @returns
79
+ */
80
+ static getLoadType(eventContext: Xrm.Events.EventContext): Promise<XrmEnum.FormDataLoadState>;
81
+ /**
82
+ * Switches the form to the specified form id, if it exists
83
+ * @param formId
84
+ * @param formContext
85
+ */
86
+ static switchForms(formId: string, formContext: Xrm.FormContext): Promise<void>;
87
+ /**
88
+ * Locks the form for editing by disabling all controls
89
+ * @param formContext
90
+ */
91
+ static lockFormForEditing(formContext: Xrm.FormContext): Promise<void>;
92
+ }
93
+ //# sourceMappingURL=Utilities.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Utilities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AAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAWrF;;;OAGG;WACU,kBAAkB,CAAE,WAAW,EAAE,GAAG,CAAC,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;CAO9E"}
@@ -0,0 +1,351 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Utilities = void 0;
4
+ const createFormConstants_1 = require("../constants/createFormConstants");
5
+ class Utilities {
6
+ /**
7
+ * Hides the form selector and the form header
8
+ * @param formContext
9
+ */
10
+ static hideFormSelector(formContext) {
11
+ /*formContext.ui.formSelector.items.get().forEach((item: Xrm.Controls.FormItem) => {
12
+ item.setVisible(false);
13
+ });*/
14
+ formContext.ui.headerSection.setBodyVisible(false);
15
+ }
16
+ /**
17
+ * Hides the form selector but show the form header
18
+ * @param formContext
19
+ */
20
+ static hideFormSelectorShowHeader(formContext) {
21
+ formContext.ui.formSelector.items.get().forEach((item) => {
22
+ item.setVisible(false);
23
+ });
24
+ }
25
+ /**
26
+ * Shows the form selector
27
+ * @param formContext
28
+ */
29
+ static showFormSelector(formContext) {
30
+ formContext.ui.formSelector.items.get().forEach((item) => {
31
+ item.setVisible(true);
32
+ });
33
+ }
34
+ /**
35
+ * Initializes the create form by hiding the header section and tab navigator.
36
+ */
37
+ static async initializeCreateForm(formContext) {
38
+ formContext.ui.headerSection.setBodyVisible(false);
39
+ formContext.ui.headerSection.setTabNavigatorVisible(false);
40
+ }
41
+ /**
42
+ * The guid id of the current form with no braces
43
+ * @param formContext
44
+ * @returns
45
+ */
46
+ static formId(formContext) {
47
+ return this.stripBraces(formContext.ui.formSelector.getCurrentItem().getId());
48
+ }
49
+ static openEditForm(eventContext, savemode, formType, widthEditForm, guidEditForm, idrecord, recordentity, recordname, parentField) {
50
+ var _a;
51
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
52
+ const ec = eventContext;
53
+ const saveEventArgs = ec.getEventArgs();
54
+ if (!saveEventArgs.getIsSaveSuccess()) {
55
+ //there was a save error
56
+ const saveError = saveEventArgs.getSaveErrorInfo();
57
+ console.log(saveError);
58
+ return;
59
+ }
60
+ const formContext = eventContext.getFormContext();
61
+ // savemode 1: save
62
+ // savemode 2: save and close
63
+ // see https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/save-event-arguments/getsavemode
64
+ if (savemode === 1 /* XrmEnum.SaveMode.Save */ && formType === 1 /* XrmEnum.FormType.Create */) {
65
+ this.switchForms(guidEditForm, formContext);
66
+ formContext.ui.headerSection.setTabNavigatorVisible(true);
67
+ /*if (widthEditForm !== undefined) {
68
+ if (formContext.data.entity.getId() !== "") {
69
+ formContext.ui.close();
70
+
71
+ const pageInput: Xrm.Navigation.PageInputEntityRecord = {
72
+ pageType: "entityrecord",
73
+ entityName: formContext.data.entity.getEntityName(),
74
+ entityId: Utilities.myId(formContext),
75
+ formId: guidEditForm,
76
+ isOfflineSyncError: false,
77
+ };
78
+ const navigationOptions: Xrm.Navigation.NavigationOptions = {
79
+ target: 2,
80
+ height: { value: 100, unit: "%" },
81
+ width: { value: widthEditForm, unit: "%" },
82
+ position: 2,
83
+ };
84
+ Xrm.Navigation.navigateTo(pageInput, navigationOptions);
85
+ }
86
+ }*/
87
+ }
88
+ // save and new from custom button (see onSaveAndNew)
89
+ else if (savemode === 13 || savemode === 59 /* XrmEnum.SaveMode.SaveAndNew */) {
90
+ formContext.ui.close();
91
+ const formParameters = {};
92
+ if (idrecord !== undefined && idrecord !== "") {
93
+ formParameters["id_record"] = idrecord;
94
+ formParameters["record_entity"] = recordentity;
95
+ formParameters["record_name"] = recordname;
96
+ }
97
+ else {
98
+ const parentLookup = (_a = formContext.getAttribute(parentField)) === null || _a === void 0 ? void 0 : _a.getValue();
99
+ formParameters["id_record"] = parentLookup && parentLookup.length > 0
100
+ ? parentLookup[0].id
101
+ : undefined;
102
+ formParameters["record_name"] = parentLookup && parentLookup.length > 0
103
+ ? parentLookup[0].name
104
+ : undefined;
105
+ formParameters["record_entity"] = parentLookup && parentLookup.length > 0
106
+ ? parentLookup[0].entityType
107
+ : undefined;
108
+ }
109
+ //open create form
110
+ const pageInput = {
111
+ pageType: "entityrecord",
112
+ entityName: formContext.data.entity.getEntityName(),
113
+ data: formParameters,
114
+ formId: formContext.ui.formSelector.getCurrentItem().getId(),
115
+ isOfflineSyncError: false,
116
+ };
117
+ const navigationOptions = {
118
+ target: 2,
119
+ height: { value: 100, unit: "%" },
120
+ width: { value: widthEditForm, unit: "%" },
121
+ position: 2,
122
+ };
123
+ Xrm.Navigation.navigateTo(pageInput, navigationOptions);
124
+ }
125
+ }
126
+ static openEditForm2(eventContext, savemode, formType, guidEditForm) {
127
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
128
+ const ec = eventContext;
129
+ const saveEventArgs = ec.getEventArgs();
130
+ if (!saveEventArgs.getIsSaveSuccess()) {
131
+ //there was a save error
132
+ const saveError = saveEventArgs.getSaveErrorInfo();
133
+ console.log(saveError);
134
+ return;
135
+ }
136
+ const formContext = eventContext.getFormContext();
137
+ // savemode 1: save
138
+ // savemode 2: save and close
139
+ // see https://learn.microsoft.com/en-us/power-apps/developer/model-driven-apps/clientapi/reference/save-event-arguments/getsavemode
140
+ if (savemode === 1 /* XrmEnum.SaveMode.Save */ && formType === 1 /* XrmEnum.FormType.Create */) {
141
+ this.switchForms(guidEditForm, formContext);
142
+ formContext.ui.headerSection.setTabNavigatorVisible(true);
143
+ }
144
+ }
145
+ static toLookup(reference) {
146
+ if (reference === undefined ||
147
+ reference.id === undefined ||
148
+ reference.name === undefined ||
149
+ reference.entityType === undefined) {
150
+ return null;
151
+ }
152
+ else {
153
+ const lookup = [
154
+ {
155
+ id: reference.id.toString(),
156
+ name: reference.name,
157
+ entityType: reference.entityType,
158
+ },
159
+ ];
160
+ return lookup;
161
+ }
162
+ }
163
+ static openAlertDialog(title, text, confirmButtonLabel, height, width) {
164
+ return new Promise((resolve, reject) => {
165
+ Xrm.Navigation.openAlertDialog({ confirmButtonLabel: confirmButtonLabel, text: text, title: title }, { height: height, width: width }).then((result) => {
166
+ resolve(result);
167
+ }, (error) => {
168
+ console.log(error.message);
169
+ reject(error);
170
+ });
171
+ });
172
+ }
173
+ static async retrieveEntity(entityLogicalName, id, columns) {
174
+ return new Promise((resolve) => {
175
+ Xrm.WebApi.online.retrieveRecord(entityLogicalName, id, "?$select=" + columns).then(function success(result) {
176
+ resolve(result);
177
+ }, function (error) {
178
+ const alertStrings = {
179
+ confirmButtonLabel: "OK",
180
+ text: "There was an error retrieving the entity: " + error.message,
181
+ title: "Error",
182
+ };
183
+ const alertOptions = { height: 120, width: 260 };
184
+ Xrm.Navigation.openAlertDialog(alertStrings, alertOptions);
185
+ });
186
+ });
187
+ }
188
+ static convertToOdataField(field) {
189
+ return "_" + field + "_value";
190
+ }
191
+ static convertToOdataName(field) {
192
+ return "_" + field + "_value@OData.Community.Display.V1.FormattedValue";
193
+ }
194
+ /**
195
+ * Returns the id of the current item with no braces
196
+ * @param formContext
197
+ * @returns
198
+ */
199
+ static myId(formContext) {
200
+ return Utilities.stripBraces(formContext.data.entity.getId());
201
+ }
202
+ /**
203
+ * Returns the id of the lookup field with no braces or null if not set
204
+ * @param lookupName the name of the lookup field
205
+ * @param formContext the form context
206
+ * @returns the id of the lookup field with no braces or null if not set
207
+ */
208
+ static getId(lookupName, formContext) {
209
+ var _a;
210
+ const value = (_a = formContext.getAttribute(lookupName)) === null || _a === void 0 ? void 0 : _a.getValue();
211
+ if (value !== null && value !== undefined && value.length === 1 && value[0].id !== undefined) {
212
+ var id = value[0].id;
213
+ return this.stripBraces(id);
214
+ }
215
+ return null;
216
+ }
217
+ /**
218
+ * Returns the name of the lookup field or null if not set
219
+ * @param lookupName the name of the lookup field
220
+ * @param formContext the form context
221
+ * @returns the name of the lookup field or null if not set
222
+ */
223
+ static getName(lookupName, formContext) {
224
+ var _a;
225
+ const value = (_a = formContext.getAttribute(lookupName)) === null || _a === void 0 ? void 0 : _a.getValue();
226
+ if (value !== null && value !== undefined && value.length === 1 && value[0].name !== undefined) {
227
+ return value[0].name;
228
+ }
229
+ return null;
230
+ }
231
+ /**
232
+ * Returns the parent using the id_record and record_entity fields passed in form parameters
233
+ * @param formContext the form context
234
+ * @returns a lookup to the parent record or null if the parameters are not set
235
+ */
236
+ static getParent(formContext) {
237
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j;
238
+ if (((_a = formContext.data.attributes.get(createFormConstants_1.id_record)) === null || _a === void 0 ? void 0 : _a.getValue()) !== null &&
239
+ ((_b = formContext.data.attributes.get(createFormConstants_1.record_entity)) === null || _b === void 0 ? void 0 : _b.getValue()) !== null) {
240
+ const idrecord = (_d = (_c = formContext.data.attributes.get(createFormConstants_1.id_record)) === null || _c === void 0 ? void 0 : _c.getValue()) === null || _d === void 0 ? void 0 : _d.toString();
241
+ const recordentity = (_f = (_e = formContext.data.attributes.get(createFormConstants_1.record_entity)) === null || _e === void 0 ? void 0 : _e.getValue()) === null || _f === void 0 ? void 0 : _f.toString();
242
+ const recordname = (_j = (_h = (_g = formContext.data.attributes.get(createFormConstants_1.record_name)) === null || _g === void 0 ? void 0 : _g.getValue()) === null || _h === void 0 ? void 0 : _h.toString()) !== null && _j !== void 0 ? _j : "Unknown " + recordentity;
243
+ if (idrecord === undefined || recordentity === undefined) {
244
+ return null;
245
+ }
246
+ else {
247
+ const parent = [
248
+ {
249
+ name: recordname,
250
+ entityType: recordentity,
251
+ id: idrecord,
252
+ },
253
+ ];
254
+ return parent;
255
+ }
256
+ }
257
+ return null;
258
+ }
259
+ static stripBraces(idWithBraces) {
260
+ return idWithBraces.replace('{', '').replace('}', '');
261
+ }
262
+ /**
263
+ *
264
+ * @returns the current user's id with no braces
265
+ */
266
+ static myUserId() {
267
+ return Xrm.Utility.getGlobalContext().userSettings.userId.replace(/[{}]/g, "");
268
+ }
269
+ /**
270
+ * Returns the values of the useBDRTeam field in TekStack Settings and saves it in session storage so we don't have to keep calling the API.
271
+ * If the form is the specified type and this is the initial load, closes the form and opens the specified form.
272
+ * Used to redirect to the create form from the edit form and vice versa, if we are not in the matching mode.
273
+ * @param eventContext
274
+ * @param type
275
+ * @param formId
276
+ */
277
+ static async redirectIfFormType(eventContext, type, formId) {
278
+ var _a;
279
+ const formContext = eventContext.getFormContext();
280
+ const formType = formContext.ui.getFormType();
281
+ let loadState = 1 /* XrmEnum.FormDataLoadState.InitialLoad */;
282
+ try {
283
+ const ec = eventContext;
284
+ // only available in the form load event
285
+ loadState = (_a = ec.getEventArgs()) === null || _a === void 0 ? void 0 : _a.getDataLoadState();
286
+ }
287
+ catch { }
288
+ if (formType === type && loadState === 1 /* XrmEnum.FormDataLoadState.InitialLoad */) {
289
+ this.switchForms(formId, formContext);
290
+ /*formContext.ui.close();
291
+ const pageInput: Xrm.Navigation.PageInputEntityRecord = {
292
+ pageType: "entityrecord",
293
+ entityName: formContext.data.entity.getEntityName(),
294
+ entityId: Utilities.myId(formContext),
295
+ formId: formId,
296
+ isOfflineSyncError: false,
297
+ };
298
+ const navigationOptions: Xrm.Navigation.NavigationOptions = {
299
+ target: 2,
300
+ height: { value: 100, unit: "%" },
301
+ width: { value: 60, unit: "%" },
302
+ position: 2,
303
+ };
304
+ Xrm.Navigation.navigateTo(pageInput, navigationOptions);*/
305
+ }
306
+ }
307
+ /**
308
+ * Returns the load type of the form. Only available in the form load event.
309
+ * @param eventContext
310
+ * @returns
311
+ */
312
+ static async getLoadType(eventContext) {
313
+ var _a;
314
+ let loadState = 1 /* XrmEnum.FormDataLoadState.InitialLoad */;
315
+ try {
316
+ const ec = eventContext;
317
+ // only available in the form load event
318
+ loadState = (_a = ec.getEventArgs()) === null || _a === void 0 ? void 0 : _a.getDataLoadState();
319
+ }
320
+ catch { }
321
+ return loadState;
322
+ }
323
+ /**
324
+ * Switches the form to the specified form id, if it exists
325
+ * @param formId
326
+ * @param formContext
327
+ */
328
+ static async switchForms(formId, formContext) {
329
+ const items = formContext.ui.formSelector.items.get();
330
+ for (let i = 0; i < items.length; i++) {
331
+ const item = items[i];
332
+ if (item.getId().toLowerCase() === formId.toLowerCase()) {
333
+ item.navigate();
334
+ break;
335
+ }
336
+ }
337
+ }
338
+ /**
339
+ * Locks the form for editing by disabling all controls
340
+ * @param formContext
341
+ */
342
+ static async lockFormForEditing(formContext) {
343
+ if (formContext.ui.getFormType() === 2 /* XrmEnum.FormType.Update */) {
344
+ formContext.ui.controls.forEach(function (control) {
345
+ control.setDisabled(true);
346
+ });
347
+ }
348
+ }
349
+ }
350
+ exports.Utilities = Utilities;
351
+ //# sourceMappingURL=Utilities.js.map