Skip to Content

Replacing Header with payload value using Groovy Script

Hi Experts,

I wanted to get the header value and mapping into target field in mapping using groovyscript. But i'm getting below error while tracing

com.sap.xi.mapping.camel.XiMappingException: com.sap.aii.mappingtool.tf7.MessageMappingException: Runtime exception during processing target field mapping /ns3:Trzba/ns3:KontrolniKody/ns3:pkp. The root message is: Exception:[com.sap.aii.mappingtool.tf7.rt.BehaviorInvocationException: groovy.lang.MissingPropertyException: No such property: H_headerName for class: Script16] in class com.sap.aii.mappingtool.tf7.ScriptHandler method getHeader1[pkp, com.sap.xi.mapping.camel.impl.MappingContextImpl@1f3ac163, com.sap.aii.mappingtool.tf7.rt.Context@2760de30] groovy.lang.MissingPropertyException: No such property: H_headerName for class: Script16, cause: groovy.lang.MissingPropertyException: No such property: H_headerName for class: Script16

I followed the solution provided by Sriprasad Shivaram Bhat

https://archive.sap.com/discussions/thread/3922412

Below is the script which i used

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

//Add MappingContext as an additional argument to read or set Headers and properties. def String getHeader1(String header,MappingContext context)

{ String HeaderValue = context.getHeader1(H_headerName); HeaderValue= HeaderValue.toString(); return HeaderValue; }

Please let me how to achieve it.

Regards,

Rajesh

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • Best Answer
    Jan 24 at 04:51 PM

    Hi Rajesh,

    the error message suggests there is some issues in the script.

    import com.sap.it.api.mapping.*; 
    //Add MappingContext as an additional argument to read or set Headers and properties. 
    def String getHeader1(String headerName,MappingContext context)
    { 
     String HeaderValue = context.getHeader(headerName); 
     HeaderValue= HeaderValue.toString(); 
     return HeaderValue; 
     
    } 
    

    could you please check if the above code helps!

    thanks and regards,

    Praveen T

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Praveen,

      Thank you very much its working. I had done silly mistake, after replacing H_headerName with just headerName and its working fine.

      Thanks for the help.

      Regards,

      Rajesh