1const api = this.template.querySelector('cgcloud-tpm-promotion');
2
3// Export options, the possible values can be extracted using
4// the other described methods
5const exportOptions = {
6 subsets: ["Planning"], // Subsets to request data
7 periods: [
8 "Total",
9 "Week"
10 ],
11 levels: [
12 "Total",
13 "Category",
14 "Product"
15 ],
16 format: "json"
17};
18
19// Correct Scenario
20api.getProperty('calculationStatus'); // 'VALID'
21
22api.exportKPIs(exportOptions)
23 .then((data) => {
24 // Example response as CSV
25 //
26 // kpiName,Category,Product,AP_LBL_TOTAL,03/2022,04/2022
27 // SampleKPI1,,,246,123,123
28 // SampleKPI1,01tTC0000000001AAA,,246,123,123
29 // SampleKPI1,01tTC0000000001AAA,01tTC0000000002AAA,246,123,123
30 // SampleKPI2,,,1974,987,987
31 // SampleKPI2,01tTC0000000001AAA,,1974,987,987
32 // SampleKPI2,01tTC0000000001AAA,01tTC0000000002AAA,1974,987,987
33
34 // Example response as JSON
35 //
36 // [{
37 // kpiName: "SampleKPI1",
38 // Category: null,
39 // Product: null,
40 // AP_LBL_TOTAL: 246,
41 // "03/2022": 123,
42 // "04/2022": 123
43 // }, {
44 // kpiName: "SampleKPI1",
45 // Category: "01tTC0000000001AAA",
46 // Product: null,
47 // AP_LBL_TOTAL: 246,
48 // "03/2022": 123,
49 // "04/2022": 123
50 // },{
51 // kpiName: "SampleKPI1",
52 // Category: "01tTC0000000001AAA",
53 // Product: "01tTC0000000002AAA",
54 // AP_LBL_TOTAL: 246,
55 // "03/2022": 123,
56 // "04/2022": 123
57 // },{
58 // kpiName: "SampleKPI2",
59 // Category: null,
60 // Product: null,
61 // AP_LBL_TOTAL: 1974,
62 // "03/2022": 987,
63 // "04/2022": 987
64 // },{
65 // kpiName: "SampleKPI2",
66 // Category: "01tTC0000000001AAA",
67 // Product: null,
68 // AP_LBL_TOTAL: 1974,
69 // "03/2022": 987,
70 // "04/2022": 987
71 // },{
72 // kpiName: "SampleKPI2",
73 // Category: "01tTC0000000001AAA",
74 // Product: "01tTC0000000002AAA",
75 // AP_LBL_TOTAL: 1974,
76 // "03/2022": 987,
77 // "04/2022": 987
78 // }]
79
80
81 // We can access the properties on the result:
82 const firstRecord = data[0];
83
84 console.log(firstRecord["kpiName"]); // "SampleKPI1"
85 // Since we request the total period,
86 // we can read the total period value
87 console.log(firstRecord["AP_LBL_TOTAL"]); // 246
88 // We can also read specific periods information
89 console.log(firstRecord["03/2022"]); // 123
90 // We can also know which level the row references
91 console.log(firstRecord["Category"]); // null
92 console.log(firstRecord["Product"]); // null
93 // Since Category is null, it means this data row
94 // represents the total value for KPI "SampleKPI1"
95
96 // For last record
97 const lastRecord = data[data.length - 1];
98
99 console.log(lastRecord["kpiName"]); // "SampleKPI2"
100 // Since we request the total period,
101 // we can read the total period value
102 console.log(lastRecord["AP_LBL_TOTAL"]); // 1974
103 // We can also read specific periods information
104 console.log(lastRecord["03/2022"]); // 987
105 // We can also know which level the row references
106 console.log(lastRecord["Category"]); // "01tTC0000000001AAA"
107 console.log(lastRecord["Product"]); // "01tTC0000000002AAA"
108 // Since Product is not null, it means this data row
109 // represents the value for KPI "SampleKPI2" for that
110 // specific product
111 });
112
113// Error Scenario
114api.getProperty('calculationStatus'); // 'LOADING'
115
116api.exportKPIs(exportOptions)
117 .catch((error) => {
118 console.log(error.message); // CalculationStatus is not "VALID". Current Status "LOADING"
119 });