Technology Blogs by Members
Explore a vibrant mix of technical expertise, industry insights, and tech buzz in member blogs covering SAP products, technology, and events. Get in the mix!
cancel
Showing results for 
Search instead for 
Did you mean: 
MioYasutake
Active Contributor

The following article is an English translation of an article I posted here.

In SAP Build Code, currently only projects created with SAP Build's lobby or low-code templates are supported. If you try clicking the Joule icon in a project created with the cds init command, you'll receive a "Not Available" message.

MioYasutake_2-1713561141035.png

However, the logic generation and test code generation features of Build Code are quite useful, and I wanted to try using them with existing projects.

In a Nutshell

By adding the following configuration to package.json, Joule can be enabled for existing code as well. Note, however, that this method is only effective for CAP Node.js and does not support Java.

 

 

 

 

  "lcap": true

 

 

 

 

Steps 

1. Create a project

 

 

 

 

cds init <project_name>

 

 

 

 

At this point, Joule is not yet enabled.

MioYasutake_2-1713561141035.png

2. Add Configuration to package.json

Add the following setting.

 

 

  "lcap": true

 

 

The complete configuration will look like this:

 

MioYasutake_1-1713561689637.png

3. Install dependency

Install the @Sap/low-code-event-handler module. The template-generated code will use this module as illustrated in the following example.

 

 

/**
 * Code is auto-generated by Application Logic, DO NOT EDIT.
 * @version(2.0)
 */
const LCAPApplicationService = require('@sap/low-code-event-handler');
const books_Logic = require('./code/books-logic');

class CatalogService extends LCAPApplicationService {
    async init() {

        this.after('CREATE', 'Books', async (results, request) => {
            await books_Logic(results, request);
        });

        return super.init();
    }
}


module.exports = {
    CatalogService
};

 

 

 

4. Confirm Activation of Joule

Refresh your browser and open Joule. (If you do not refresh, it will remain in the original state)

MioYasutake_2-1713561901565.png

After this, I added a data model with cds add tiny-sample, generated application logic via Joule, and deployed to Cloud Foundry to confirm that it functions correctly.

Point of Caution

Joule cannot be used with existing .js files. If you try opening Joule for event handlers that are already present, the "Open Guide" screen appears instead of Joule, and support for this source is not available.

MioYasutake_6-1713562249962.png

If you add logic from the Graphical Modeler, it will overwrite the existing source. Therefore, if there are existing sources, they need to be backed up.

MioYasutake_7-1713562298896.png

Conclusion

By simply adding a configuration to package.json, Joule can be activated for existing CAP Node.js projects, making it a more useful tool for pro-code developers.

Labels in this area