cancel
Showing results for 
Search instead for 
Did you mean: 

How can I access ImpEx variables from ImpEx BeanShell code

former_member1336901
Participant
0 Kudos

Suppose I have an ImpEx file which defines an ImpEx variable ("$variable=value"). How can I access such an ImpEx variable from BeanShell code in the same ImpEx file?

As a simple example, let's assume I have

 $cronjob=abc
 
 #% import de.hybris.platform.core.Registry
 #% import de.hybris.platform.servicelayer.cronjob.CronJobService
 #% CronJobService cronJobService = Registry.getApplicationContext().getBean("cronJobService")
 #% cronJobService.performCronJob(cronJobService.getCronJob("xxx"),true)

How can I access the value of "$cronjob" in the BeanShell code (instead of "xxx")?

Accepted Solutions (1)

Accepted Solutions (1)

andyfletcher
Active Contributor
0 Kudos

It replaces all of the macros before running your code so just use $cronjob

e.g.

 $cronjob=abcd
 #% java.lang.System.out.println("$cronjob");

Prints abcd to stdout.

former_member1336901
Participant
0 Kudos

I thought the replacement would not happen in BeanShell code.

Thanks!

andyfletcher
Active Contributor
0 Kudos

Yeah me too. I was posting an answer showing how to abuse beanshell's setAccessiblity(true) method and couldn't understand why it wasn't working.

 $cronjob=abc
 #% setAccessibility(true)
 #% cronjob = impex.definitions.get("$cronjob")
 #% java.lang.System.out.println(cronjob)

kept printing null, until I realised that is was actually running

 #% cronjob = impex.definitions.get("abc")

because the macro had been replaced and the answer became much simpler!

former_member1336901
Participant
0 Kudos

Ah, impex.definitions.get(...) is the way to go then.

You could have used

.get("$"+"cronjob")

;-)

Answers (0)