Skip to Content
0

Replacing Header with payload value using Groovy Script

Jan 24 at 04:32 PM

244

avatar image

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Best Answer
Praveen Tirumareddy
Jan 24 at 04:51 PM
0

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

Show 1 Share
10 |10000 characters needed characters left 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

0