cancel
Showing results for 
Search instead for 
Did you mean: 

Error in extending application for SAP S/4HANA Cloud using CAP

08-10-2021 7:57 AM
nkaur1311 Explorer
39669 views 2 comments Go to solution
0 Likes
SAP Managed Tags
Subscribe

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.

0 Likes

Accepted Solutions (1)

Accepted Solutions (1)

Junjie
Product and Topic Expert
Product and Topic Expert

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

Junjie
Product and Topic Expert
Product and Topic Expert
0 Likes

Hi nkaur06,

if my answer solves your issue. Please accept it. Thank you.

Answers (0)