cancel
Showing results for 
Search instead for 
Did you mean: 
Read only

How to read dynamicly a global variable using Groovy Script?

veenagayathri
Explorer
0 Likes
5,284

Hello friends,

I have a scenario in my development, In an integration flow, I need to access and modify few global variables (I created these global variables in another integration flow)

In flow 1: Using general splitter, I created global variables with the help of write variables adapter. You can see this from the attached file of .writevariable.png

In flow 2: I used a content modifier with a source type as "Global Variable" and source value as "${header.globalname}" contentmodifier.png.

But when I tried to read these global variables in flow 2, this doesn't seem to work.

Is there any solution for this?

Is it posiible to access these variables via Groovy Script?

Thank you!

View Entire Topic
asutoshmaharana2326
Active Participant
0 Likes

Dear Veena,

We can not use camel Simple expression as a value for a parameter defined in content modifier with a source type as "Global Variable" or "Local Variable". It's a limitation as of now in SAP CPI.

So I have found a clever alternative for that either if you are setting up some values in global variable in you 1st iFlow then I would recommend you to create a HashMap with all the global patameter's name and it's value using Groovy and then create only one global variable using write step and assign your HashMap to that.

Luckily we can assign objects to the values in Write variable step.(Do it via HashMap->Property->Global Variable)

Then in the 2nd iFlow you can retrieve the global variable and then use another groovy to fetch your required parameter's value from the HashMap.

If you follow it properly, you will surely get your dynamic global variables 🙂

Thanks,

Asutosh Maharana

asutoshmaharana2326
Active Participant
0 Likes

As per SAP Note 3014782, assigning camel simple expression for Global variable is not supported in content modifier. But today i have tried and i think right now expressions are also supported. May be your tenant has lower camel core version that's why it's not working but you can anyhow implement the trick I have mentioned above if your tenant do not support.

veenagayathri
Explorer
0 Likes

Hi Asutosh,

Good thinking!

Thank you very much for your answer!!!

I will definitely try this too and let you know about it.

With these I would like to say that, I got 3 solutions for my issue.

  • First one: We can create a groovy script to access the variable names by value mapping and set the variable name to header. Later on, we can add the Pallet "Get" by "Data Store Operations" and after getting the payload, set the values to the header. (This worked in my case. As I have all the required values in my payload itself)
  • Second one: We can use the Pallet "Select" by "Data Store Operations" and after getting the payload, We can use a General Splitter to split and access the value from payload, then set the multiple header values to complete the process. (This also worked in my case)
  • Third one: We can simply follow the rule said by asutoshmaharana2326 .

Regards,

Veena