Hello Experts,
I am working on a CAP based project wherein I am consuming external services from S/4 HANA. I am able to retrieve the data from external services by using custom handlers in the js file.
However, my requirement is to create/post the data in the external service. Therefore, following the blog Extend CAP using cloud SDK, I have written the code as:
this.on('CREATE', WorkPackageCreateSet, async (req) => {
try {
const payload = buildAddressForCreate(req);
const result = await WorkPackageSet
.requestBuilder()
.create(payload)
.execute(sdkDest);
return prepareResult(result);
} catch (err) {
req.reject(err);
}
});
const { WorkPackageSet } = require("@sap/cloud-sdk-vdm-commercial-project-detail-service");
const _prepareBody = (address) => {
return {
ProjectID: address.ProjectID,
WorkPackageID: address.WorkPackageID,
WorkPackageName: address.WorkPackageName,
Description: address.Description,
WPStartDate: address.WPStartDate,
WPEndDate: address.WPEndDate,
WorkPackageType: address.WorkPackageType
}
}
//create payload
const buildAddressForCreate = (req) => {
const address = WorkPackageSet.builder().fromJson(_prepareBody(req.data));
if (req.params[0]) {
const { ProjectID } = req.params[0];
address.ProjectID = ProjectID;
}
return address;
}
While posting the data, WorkPackageSet in buildAddressForCreate is appearing undefined. Although I have installed all the dependencies, I am getting the below issue:
[cds] - POST /masterdata/WorkPackageCreateSet
[INTERNAL ERROR] TypeError: Cannot read property 'builder' of undefined
If anyone has worked on any such scenario or if I am missing something, Please suggest.
Regards,
Navneet Kaur.
Request clarification before answering.
Hi Navneet Kaur,
I guess you should use "WorkpackageSet" (with the "p" in lower case) instead of "WorkPackageSet".
You can always find the proper class name by checking the installed packages in the "node_modules".
Please feel free to create an issue here next time for the SAP Cloud SDK for JavaScript as an official support channel.
BR,
Junjie
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 5 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.