cancel
Showing results for 
Search instead for 
Did you mean: 

How to reuse or modularize JavaScript in SAP CPI?

05-26-2026 3:54 PM
290 views 0 comments
0 Likes
SAP Managed Tags
Subscribe

Introduction

As described in the article Modularising CPI Groovy scripts using POGO , there is a concept of splitting code into smaller modules by using multiple scripts within an ifFow. However, the explanation applies only to Groovy.

I am looking for a similar approach using JavaScript, which is also available in SAP CPI.

POC - additional function outside of 'processData'

As a first step, I prepared POC using a single script. It contains the main function (processData) and an additional helper function defined outside of it. Script below : 

Integration12345_0-1779801968727.png

This approach works correctly. After testing via Postman, i received the expected results. 

Integration12345_1-1779802023091.pngIntegration12345_2-1779802027440.png

POC - additional code as a seperate script (failure result)

In the next step, I tried to move the helper logic into separate script to improve readability and maintainability.. So i copied the code into a new script called "JS_ExtScript". Then in my main script "JS_withExtScript", I attempted to use the "importClass" syntax with the path src.main.resources.script.<script_name>.<class_name> .

Integration12345_3-1779802254556.png

Integration12345_4-1779802257278.png

However, the tests ended with an error . 

Integration12345_5-1779802311125.pngIntegration12345_6-1779802314511.pngIntegration12345_7-1779802321584.png

 

I did some research and found the following resources: 

Try use JavaScript scripting instead of Groovy scripting in your CPI project , where someone from SAP recommended to check functions like defineClass, load, loadClass, but none of these worked in my case. 

Integration12345_8-1779802646794.png

SAP Integration Suites javascript load library, similar question regarding my topic was raised, but no clear solution was provided. The author ended up keepin all logic in a single script, similar to my initial POC which works fine but this is not what i am looking for.

 

Has anyone successfully implemented modular JavaScript in SAP CPI (e.g. using multiple scripts or reusable libraries)?
Any suggestions or workarounds would be greatly appreciated.

Looking for you help. Thanks in advance ! 

 

 

 

 

 

 

 

 

 

0 Likes

Accepted Solutions (0)

Answers (0)