Skip to Content
Technical Articles

Using Script Collection across various Integration Flows in a Package in SAP CPI

Code reusability is one of the strongest feature of any tool. Earlier SAP Cloud Integration was lacking a prime feature of script reusability like we used to reuse the objects of different software component versions in SAP PI/PO. Till now we were creating same script in many flows as Scripts were referred locally by an Integration flow. We were keeping redundant code on the server like logging payload/headers etc.

But now this issue has been addressed in SAP CPI and script reusability feature is available in Integration Suite to avoid redundant script writing. We can create multiple scripts under one artifact ( script Collection) and that can be called in multiple packages/integration flows

This blog will illustrate the steps to create a script collection and using the underlying script in any package/integration flow.

Step 1: Go to Package -> Edit -> Add Artifact -> Scrip Collection

 

Step 2: Put the name and description of the collection

Step 3: Click on Script collection & edit. Create the Groovy or Java Script repository under this artifact.

Step 4: Create required reusable Java/Groovy scripts.

Step 5: Save and Deploy the artifact.

Now we

Step 6: Go to Integration flow where you want to use script collection. Click on Resources tab. Under that References and Add References.

 

Step 7: Add the Script Collection References. It will list down all the packages those are having Script Collection. Select your package and Script Collection to create a reference link.

Once library is added. It will be visible under reference tab. You can see the package name once you hover the mouse on collection name.

 

Step 8: Now simply add Groovy/Java Script palette and assign the script from reference tab. It will list down all the scripts available in script collection artifact.

 

Step 9: Save and Deploy the Flow and Script Collection artifact

Step 10: Trigger the test payload from Postman and you can see the logPayload scrip will be executed from the referenced package/artifact/Script Collection

 

 

SAP has delivered very nice and much awaited feature but it still it needs some refinement.

  • After deploying the script library it should show where used feature so that any developer can find the interfaces those are using a specific script or script collections.
  • Currently, Script Collection created in package can be used in different integration flows

 

 

5 Comments
You must be Logged on to comment or reply to a post.
  • Hi Rahul

    For now, you can only access scripts in a script collection from within the same package. Sharing scripts across packages will be added later.

    Regards,

    Morten

    • Thanks Morten,

      I have updated the blog. That seems a big restriction. Do you know when SAP is releasing the feature where we can access collection across various packages ?

       

  • Hi Rahul,

    we wrote a local groovy script with a "helper"-class and many helping functions (like conversions etc):

     

    package src.main.resources.script
    
    public class Helper{
    
       static void convertXYZ(){
          ... do something
       }
    }

    Yet this script is called in some other scripts in the same iflow by importing the script and afterwards by calling the different methods like in this example:

    import src.main.resources.script.Helper
    
    def Message processData(Message message){
       Helper.convertXYZ()
       return message
    }

    We now want to put this helper class in a script collection and calling its methods directly from a local groovy.
    In your example I only see that you call a method from a reference instead of a local groovy. But we want to call a method from a reference IN a local groovy.

    Is there a similar way how to import and use these methods?

     

    Best regards

  • Hello everyone! A very cool feature!

    But what about scripts (custom function) in the mapping?

    They also repeat from IFlow to IFlow

     

    Best regards