Skip to Content

Dynamic Value Mapping in SAP CPI


Recently came across multiple SCN threads looking for how to deal with dynamic value mapping in SAP CPI,so this is how you can achieve the same with small example.


We will use POSTMAN HTTP client to push some message and get the transformed output using value mapping api ( after value mapping performed ).

Creation of Integration Artifact:

Create an IFlow having below steps as described.

Step 1:

Create a HTTP Sender Communication Channel

Step 2:

Add mapping step following below.

Input and Output Structure:

Mapping Overview of field containing value mapping:

Create a custom function to call the ValueMappingApi Mapping Java API[ Mapping API ] which internally calls the Value Mapping project and gets the required output.

Creation of Custom Function:

Custom Function Script:

Copy paste the below code in Window opened in #4 of Custom function creation.


/*Add MappingContext parameter to read or set headers and properties
def String customFunc1(String P1,String P2,MappingContext context) {
         String value1 = context.getHeader(P1);
         String value2 = context.getProperty(P2);
         return value1+value2;

Add Output parameter to assign the output value.
def void custFunc2(String[] is,String[] ps, Output output, MappingContext context) {
        String value1 = context.getHeader(is[0]);
        String value2 = context.getProperty(ps[0]);

def String dynamicValueMap(String sAgency, String sSchema, String tAgency, String tSchema, String key){

def service = ITApiFactory.getApi(ValueMappingApi.class, null);

if( service != null) {

String val= service.getMappedValue(sAgency, sSchema, key, tAgency, tSchema);
if ( val.equals("") || val ==null )
    return "default"
    return val

return null;


Step 3:

Add intermediate step ( optional ) Write if you want to check the transformed output ( although you get it as response in POSTMAN ).

Step 4:

Save and Deploy your IFlow.

Creation of Value Mapping Artifact:

Create value mapping which can be referred dynamically in your script based on the input you have sent.

My value mapping looks like ( simple one:) )

Save and deploy it.Now we are good to go with our testing.

Testing with some successful transformation screenshots:

Further Enhancements:

  • Even further enhancements can be done to this scenario instead of passing schema & agency you can send some unique no and in later stage of transformation( Custom Function ) manipulate which Value Mapping to be used.
  • You can handle failure case of value mapping ( in our case I have hard coded “default” for failure case) by passing custom key or default value in input payload.


[1] Java Mapping API Help


Hope this is helpful..!


Sriprasad Shivaram Bhat

You must be Logged on to comment or reply to a post.
  • Hi Sriprasad,


    Thanks for Info, For this scenario Value Mapping and IFLOW artifacts should be in same package or it will work in different package?

  • Hello Experts,

    Can you please tell me how to create a value mapping from the csv file or valuemapping.xml file automatically. As above blog for getting the value mapping entry by passing the source value.My scenario, as SuccesFactors daily runs by query and need to update/create the value mapping table. Any suggestions are appreciated. Thanks

  • Hi Sriprasad,

    is it possible to map one source field to multiple source fields using a custom function ? What I need to reach is the following :the custom function is making API call to get a few values that have to be mapped to multiple source field.

    thanks, Radim

  • Dear Sriprasad,

    I am a very beginner to CPI, I tried the same step by step execution as shown in your blog. But i am not getting the desired output. I think the value mapping call is not happening. Below is the output i am getting.

    Input Value:


    output Value:

    <?xml version="1.0" encoding="UTF-8"?>
    The default value in the output is coming from the script. Please help to resolve this.