cancel
Showing results for 
Search instead for 
Did you mean: 

Insert a Value from Request to Response in HCI

markbernabe
Active Participant
0 Kudos

Hi HCI Experts,

I'm trying to build a scenario in HCI that would insert a value from a request message to a response message. In PI, this can be achieved using GetPayloadValueBean and PutPayloadValueBean. I'm looking into Content Modifier, Externalized Parameters or Variable which are all standard message transformers/objects in HCI. However, I'm getting no luck so far when trying to deploy the iFlow.

So far I've tried using the Write Variables. Here's my iFlow:

It's not working. It's either the Variable is not working / getting saved or I messed up with the Content Modifier. How do you fill up the message in the Body tab of the Content Modifier? The example in the guide is too simple. What if we need to assign the Variable's value in an existing field of a message payload such as my case?

What I did so far is copy pasted the whole message payload (this is the actual response message of the 1st Request-Reply from COD) and assigned the placeholder of the variable in one of the fields.

Has anyone ever done this scenario with success?

Again, appreciate any inputs.

Thanks in advance.

Mark

Accepted Solutions (1)

Accepted Solutions (1)

Sriprasadsbhat
Active Contributor
0 Kudos

Hello Mark,

Instead of Write variable you can use Content Modifier and save the value in Property like below.

In the second Content modifier call the value by adding  ${property.Prop_SenderTechnicalID}.

Reason for using Property is ,property will be retained after External Call[ RequestReply ], where as value stored in Header will get erased.

Regards,

Sriprasad Shivaram Bhat

bhavesh_kantilal
Active Contributor
0 Kudos

Hi Sriprasad,

  • The Variable would also work. Variable is nothing but a property in itself.
  • What you mentioned is applicable only for Headers but Variables are properties and not headers!
  • I had tried this before recommending this as you would see in this thread and its results . The Property is set in the 1st Content Modifier, post which a request reply is done and then the next content modifier accesses this property.
  • Also, yes properties can also do the trick like you have mentioned..

Mark,

  • Can you share the Write Variables step details?
  • Did you check the output of your Content Modifer step by enabling Header and Payload Trace? Can you share the runtime payload of the content modifier step?
  • In your context - typically, what I would do is set your targetField in message mapping where this value is required as a constant ${header.variable1}. While I havent tried this, I think in the runtime this should then get replace with the correspnding value.

Regards

Bhavesh

markbernabe
Active Participant
0 Kudos

Hi Sriprasad,

Thanks for the feedback! I've tried your recommendation unfortunately, it's still not working. There's no error in the message monitoring nor in the logs. The iFlow is deployed successfullly and message is COMPLETED. However, I didn't get the expected result of the web service call to ERP_WS. Something must have gone wrong. I'm still unsure about the Body in the Content Modifier. Did I do it correctly?

markbernabe
Active Participant
0 Kudos

Hi Bhavesh,

This is my Write Variable.

No trace payload is available Still working with SAP to get the trace capability working.

You mean set it as constant in the mapping right? And no need for a Content Modifier before the mapping.

Let me try this.

Thanks

bhavesh_kantilal
Active Contributor
0 Kudos

Hello Mark,

This is what I meant. Unfortunately no idea why it doesnt seem to work on your end.

Getting the trace is definitely what will help get more context to why this is failing!

One question - How are you quantifying that this payload is not getting replaced if you do not have trace enabled?

Regards

Bhavesh

markbernabe
Active Participant
0 Kudos

Hi Bhavesh,

Right. Will update you know once I get this trace sorted out.

That's my assumption because the end result of the service call to ECC is a table update. When I use a constant value in the mapping, the table gets updated successfully. But when I replace it with the variable/content modifier, there's no update, even if the iFlow/message monitoring says it's successful and no error.

Thank you.

markbernabe
Active Participant
0 Kudos

Hi Bhavesh,

Finally got the trace feature to work.

So based on the response payload of the 2nd MM (in Red), it looks like the value that is expected to be the constant value that I've set in the Write Variable is not getting passed correctly during runtime as it still shows ${header.ExternalID}.

bhavesh_kantilal
Active Contributor
0 Kudos
  • Okie, so looks like the HCI Message Mapping just treats this as a Constant
  • What I can think of is write a Grooy Script that reads this property and then replaces ${header.ExternalID} with the actual value that you have read..

    Regards

    Bhavesh

    Sriprasadsbhat
    Active Contributor
    0 Kudos

    Hello Mark,

    Mapping step wont replace the headers and Properties directly in runtime.I mean ${header.H1} willnot 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.

    To Retrieve the Header Value in Message Mapping:

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

    def String getHeader1(String header,MappingContext context)

    {

      String HeaderValue = context.getHeader(H_headerName);

      HeaderValue= HeaderValue.toString();

      return HeaderValue;

    }


    To Retrieve the Property Value in Message Mapping:


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


    def String getProperty(String propertyName,MappingContext context)

    {

      String PropertyValue= context.getProperty(Prop_propertyName);

      PropertyValue= PropertyValue.toString();

      return PropertyValue;

    }

    Regards,

    Sriprasad Shivaram Bhat

    markbernabe
    Active Participant
    0 Kudos

    Thanks Sriprasad! Is this the so called Groovy script? I have no idea how this works so far. Is there any guide out there that discuss how to create UDFs in HCI?

    Sriprasadsbhat
    Active Contributor
    0 Kudos

    Hello Mark,

    Find the below links.

    Go to SAP HCI-PI Help Page and navigate like below

    Managing Integration Content-->Developing Integration Content Using the Integration Designer-->Developing Integration Flows and Projects-->Using Custom Functions in Message Mapping

    https://uacp.hana.ondemand.com/http.svc/rc/PRODUCTION/93810d568bee49c6b3d7b5065a30b0ff/1/en-US/frame...

    https://uacp.hana.ondemand.com/http.svc/rc/PRODUCTION/93810d568bee49c6b3d7b5065a30b0ff/1/en-US/frame...

    Regards,

    Sriprasad S Bhat

    bhavesh_kantilal
    Active Contributor
    0 Kudos

    Excellent Sriprasad. Wasnt aware of this feature!

    Regards,

    Bhavesh

    markbernabe
    Active Participant
    0 Kudos

    Hi Sriprasad,

    Thanks! It's really helpful.

    I've created getExternalID.gsh based on the script for Property you've provided. What value should I pass now as argument?

    Sriprasadsbhat
    Active Contributor
    0 Kudos

    Hello Mark,

    Please pass the Property Name or Write Variable Name as input to the Custom Function in Message Mapping like below.

    Message Mapping:

    Where Value of H_ErrorText in constant referring to property declared in Content Modifier like below.

    Content Modifier:

    During Run-time value stored in above property will be passed to target field in message mapping.

    In general it is something like Message (Target Field ) = ${property.H_ErrorText}.

    Regards,

    Sriprasad Shivaram Bhat

    markbernabe
    Active Participant
    0 Kudos

    Thank you so much Sriprasad! It worked perfectly!

    markbernabe
    Active Participant
    0 Kudos

    Bhavesh, thanks as well for all your inputs! I really appreciate it.

    0 Kudos

    Hello Sriprasad,

    We have a requirement to save the entire request payload for reporting purpose. We have tried using both the variable and the process property, it works in some cases and doesnt work in others. In cases where it doesnt work, junk characters are updated in the property value. For each of the cases we are saving the output of message mapping directly into the variable/property.

    Any ideas why this could be happening, i cannot put in the payload in here, as its confidential HR data.

    Regards,

    Diptee

    Answers (0)