Skip to content

Commit b9a0d3a

Browse files
committed
2 parents 8cbae9b + 72be5a0 commit b9a0d3a

File tree

4 files changed

+35
-35
lines changed

4 files changed

+35
-35
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ The guidance is divided into several groups of tutorials when published on the [
5555

5656
- [Consume Remote Services from a Mock Server in Your Full-Stack CAP Application Following the SAP BTP Developer's Guide and Deploy to SAP BTP, Cloud Foundry Runtime](). This group includes the following tutorials:
5757
- [Introduction to Remote Service Connectivity](https://developers.sap.com/tutorials/remote-service-intro.html)
58-
- [Get the Business Partner API and Extend the Incident Management Application](https://developers.sap.com/tutorials/remote-service-extend-cf.html)
58+
- [Get the Business Partner API and Extend the Incident Management Application](https://developers.sap.com/tutorials/remote-service-extend.html)
5959
- [Test the Extended Incident Management Application with the Business Partner API](https://developers.sap.com/tutorials/remote-service-run-dev-test.html)
6060
- [Install a Mock Server in the SAP BTP, Cloud Foundry Runtime](https://developers.sap.com/tutorials/remote-service-set-up-mock-cf.html)
6161
- [Deploy and Run the Incident Management Application in the SAP BTP, Cloud Foundry Runtime with a Mock Server](https://developers.sap.com/tutorials/remote-service-deploy-with-mock-cf.html)
6262

6363
- [Consume Remote Services from S/4HANA Cloud in Your Full-Stack CAP Application Following the SAP BTP Developer's Guide and Deploy to SAP BTP, Cloud Foundry Runtime]() This group includes the following tutorials:
6464
- [Introduction to Remote Service Connectivity](https://developers.sap.com/tutorials/remote-service-intro.html)
65-
- [Get the Business Partner API and Extend the Incident Management Application](https://developers.sap.com/tutorials/remote-service-extend-cf.html)
65+
- [Get the Business Partner API and Extend the Incident Management Application](https://developers.sap.com/tutorials/remote-service-extend.html)
6666
- [Test the Extended Incident Management Application with the Business Partner API](https://developers.sap.com/tutorials/remote-service-run-dev-test.html)
6767
- [Configure Connectivity Between SAP S/4HANA Cloud and SAP Business Technology Platform](https://developers.sap.com/tutorials/remote-service-configure-connectivity.html)
6868
- [Deploy and Run the Application on Cloud Foundry with SAP S/4HANA Cloud Backend](https://developers.sap.com/tutorials/remote-service-deploy-to-cf.html)

tutorials/add-custom-logic/add-custom-logic.md

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,14 @@ In this tutorial, you add some custom code to the CAP application. Depending on
5151
}
5252

5353
changeUrgencyDueToSubject(data) {
54-
if (data) {
55-
const incidents = Array.isArray(data) ? data : [data];
56-
incidents.forEach((incident) => {
57-
if (incident.title?.toLowerCase().includes("urgent")) {
58-
incident.urgency = { code: "H", descr: "High" };
59-
}
60-
});
61-
}
54+
let urgent = data.title?.match(/urgent/i)
55+
if (urgent) data.urgency_code = 'H'
6256
}
6357

6458
/** Custom Validation */
6559
async onUpdate (req) {
66-
const { status_code } = await SELECT.one(req.subject, i => i.status_code).where({ID: req.data.ID})
67-
if (status_code === 'C')
68-
return req.reject(`Can't modify a closed incident`)
60+
let closed = await SELECT.one(1) .from (req.subject) .where `status.code = 'C'`
61+
if (closed) req.reject `Can't modify a closed incident!`
6962
}
7063
}
7164
module.exports = { ProcessorService }

tutorials/build-cap-app/build-cap-app.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ You've configured the SAP Business Application Studio. Follow the steps in the [
206206
key ID : String;
207207
firstName : String;
208208
lastName : String;
209-
name : String = firstName ||' '|| lastName;
209+
name : String = trim(firstName ||' '|| lastName);
210210
email : EMailAddress;
211211
phone : PhoneNumber;
212212
incidents : Association to many Incidents on incidents.customer = $self;

tutorials/remote-service-extend/remote-service-extend.md

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ For this scenario, you use the Business Partner API from SAP S/4HANA Cloud.
147147

148148
4. Add the custom handler implementation after the **init()** method:
149149

150-
```js[9-37]
150+
```js[9-44]
151151
async init() {
152152
this.before("UPDATE", "Incidents", (req) => this.onUpdate(req));
153153
this.after("READ", "Incidents", (data) => this.changeUrgencyDueToSubject(data));
@@ -158,26 +158,33 @@ For this scenario, you use the Business Partner API from SAP S/4HANA Cloud.
158158

159159
async onCustomerRead(req) {
160160
console.log('>> delegating to S4 service...', req.query);
161-
const top = parseInt(req._queryOptions?.$top) || 100;
162-
const skip = parseInt(req._queryOptions?.$skip) || 0;
163-
164-
const { BusinessPartner } = this.remoteService.entities;
161+
let { limit, one } = req.query.SELECT
162+
if(!limit) limit = { rows: { val: 55 }, offset: { val: 0 } } //default limit to 55 rows
165163

164+
const { BusinessPartner } = this.remoteService.entities;
165+
const query = SELECT.from(BusinessPartner, bp => {
166+
bp('*');
167+
bp.addresses(address => {
168+
address('email');
169+
address.email(emails => {
170+
emails('email');
171+
});
172+
});
173+
}).limit(limit)
174+
175+
if(one){
176+
// support for single entity read
177+
query.where({ ID: req.data.ID });
178+
}
166179
// Expands are required as the runtime does not support path expressions for remote services
167-
let result = await this.S4bupa.run(SELECT.from(BusinessPartner, bp => {
168-
bp('*'),
169-
bp.addresses(address => {
170-
address('email'),
171-
address.email(emails => {
172-
emails('email');
173-
});
174-
})
175-
}).limit(top, skip));
176-
180+
let result = await this.S4bupa.run(query);
181+
177182
result = result.map((bp) => ({
178183
ID: bp.ID,
179184
name: bp.name,
180-
email: bp.addresses[0]?.email[0]?.email
185+
email: (bp.addresses[0]?.email[0]?.email || ''),
186+
firstName: bp.firstName,
187+
lastName: bp.lastName,
181188
}));
182189

183190
// Explicitly set $count so the values show up in the value help in the UI
@@ -233,23 +240,23 @@ For this scenario, you use the Business Partner API from SAP S/4HANA Cloud.
233240
const newCustomerId = req.data.customer_ID;
234241
const result = await next();
235242
const { BusinessPartner } = this.remoteService.entities;
236-
if (newCustomerId && (newCustomerId !== "") && ((req.event == "CREATE") || (req.event == "UPDATE"))) {
243+
if (newCustomerId && newCustomerId !== "") {
237244
console.log('>> CREATE or UPDATE customer!');
238245

239246
// Expands are required as the runtime does not support path expressions for remote services
240247
const customer = await this.S4bupa.run(SELECT.one(BusinessPartner, bp => {
241-
bp('*'),
248+
bp('*');
242249
bp.addresses(address => {
243-
address('email', 'phoneNumber'),
250+
address('email', 'phoneNumber');
244251
address.email(emails => {
245252
emails('email')
246-
}),
253+
});
247254
address.phoneNumber(phoneNumber => {
248255
phoneNumber('phone')
249256
})
250257
})
251258
}).where({ ID: newCustomerId }));
252-
259+
253260
if(customer) {
254261
customer.email = customer.addresses[0]?.email[0]?.email;
255262
customer.phone = customer.addresses[0]?.phoneNumber[0]?.phone;

0 commit comments

Comments
 (0)