cancel
Showing results for 
Search instead for 
Did you mean: 

Base64 Decoder With Groovy Script

mark_fryu
Participant
0 Kudos
373

hello all, can someone provide me a groovy script that allows to do the base64 Decoder?

It must do the same thing that the standard block does:

mark_fryu_0-1722874050427.png

 

but I need a groovy script code because I only need to change part of the payload

 

thank you

Distinct_Sky
Explorer
0 Kudos
Can you split the data between what needs to be encoded and what not?
mark_fryu
Participant
0 Kudos

hi @Distinct_Sky 

yes I can, but the part to be decoded is in the middle, at the beginning and at the end there are parts that must not be decoded. For this reason if I use the standard block "Base64 Decoder" it goes into error

UserID276461
Explorer
0 Kudos
// Groovy Function to decode Base64 input to String def base64Decode(encodedString){ byte[] decoded = encodedString.decodeBase64() String decode = new String(decoded) return decode } https://veereshkumarn.medium.com/groovy-base64-encode-decode-input-string-9749072a92da
View Entire Topic
Distinct_Sky
Explorer
0 Kudos

In that case, I would suggest to do it in the field level Message mapping. The below code is for SAP PI, but can be used in CPI as well.

Solved: Decode Base64 at field level! - SAP Community

mark_fryu
Participant
0 Kudos

hi @Distinct_Sky 

I tried but I get this error:

mark_fryu_1-1722931962495.png

 

This is my payload:

 

mark_fryu_2-1722932019567.png

 

 

This is the groovy script:

 

mark_fryu_0-1722932417549.png