Technology Blog Posts 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
1,802

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 @Sisn/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.

4 Comments
KazuhikoTakata
Active Participant

Hi @MioYasutake san,

Thanks for you tips. Joule is working in my existing repositories too 😃.

By the way, in which situation will you use Joule to support your coding?

(I feel experts like you are thinking coding is faster than writing prompt and reviewing result. 😎)

In my case, I had hard time to how to write code (for example: how to filter OData record to only my created ones), so this solution will help me in the future.

 

MioYasutake
Active Contributor
0 Kudos

@KazuhikoTakata 

Thank you for your comment. I might use Joule to generate event handlers or unit tests initially, then modify the code to meet my requirements.

Recently, I conducted extensive validation of Joule on Build Code, and I agree with your observation: coding myself is faster than writing prompts and reviewing the results. Additionally, while watching the webinar below, I was surprised by the volume of a single prompt required to generate a moderate quality of code.

https://community.sap.com/t5/technology-blogs-by-sap/develop-with-joule-in-sap-build-code/ba-p/13695...

I don't think I'll spend much time refining prompts to generate the exact code I want. Instead, as I mentioned initially, I will use Joule to generate the first version of event handler and unit test code.

KazuhikoTakata
Active Participant
0 Kudos

@MioYasutake san,

Thanks, I agree with your idea to generate initial version of code (event handler), because I frequently forget is "how to start writing code in this?". When initial version is provided, it is not so difficult to modify what I want to do.

T1mey
Active Participant
0 Kudos

Hi,

 

converted my project but get an error message when using / command for changing app logic.

Command failed: cds c /home/user/projects/Project/srv/service.cds -o /home/user/projects/Project/srv/service.cds.json --to json --parse Couldn't find a CDS model for '/home/user/projects/Project/srv/service.cds' in /local/source/openvscode-server

We do not have a service.js, nor service.js. Our service is described in multiple files called like the service name. (e.g Applications.js / Application.cds)

Any idea what we're doing wrong? 

Labels in this area