Monday, 19 February 2018

Add header/property values in the message mapping in SAP HCI

Mapping step won’t replace the headers and Properties directly in runtime. As ${header.H1} will not be replaced with value of H1 directly, you need to write CustomFunction( UDF in SAP PI terminology) like below and call those in Message Mapping.

If you are using WriteVariable select the type as Property and set the value for that, later call it in mapping using below script.


If you are using Content Modifier, set the Property and later call it using below script as shown.


Content modifier: (used xpath variable for Status)




In mapping, pass the input as the value maintained in the content modifier(used Status here):



Use the below groovy script and pass the constant values as Status here, no change in the below code, you can directly use it.

import com.sap.it.api.mapping.*

def String getProperty(String propertyName,MappingContext context)

{
  String PropertyValue= context.getProperty(propertyName);

  PropertyValue= PropertyValue.toString();

  return PropertyValue;

}
Below is the data received after the mapping for Status as Success:



Let me know in comments if any issues.

Happy Learning!!!



5 comments:

  1. Thank you. Your appreciation helps me motivated.

    ReplyDelete
  2. Hi Loganathan,
    I'm really amazed the way you have taken up all important CPI related requirements. This piece of code is really helpful in place of using Parallel Multicast & join etc. You have saved my time and helped to improve the performance in my integration flow.
    Thanks a ton.

    ReplyDelete
  3. Please write blog on how to set Header for post message,I have to use API token authentication ,

    ReplyDelete
  4. Hi Chetan,

    Try to check this link for adding the API Key in Header: https://saphcidemo.blogspot.com/2019/05/setting-http-header-for-api-key-in-sap.html

    ReplyDelete