How do I set the value of a provided variable of a rule in an 'Execute custom PHP code' action. I tried:

$provide_var = "Same value";

But when I try accessing this variable from the calling rule, it is empty.

Comments

altavis’s picture

Component: Rules Core » Rules Engine

I'm also interested in this.

For now I'm setting variable by php evaluation on variable creation. Data selector needs to be set for any token and in php evaluation changed:

$value = "some value";
return $value;
jun’s picture

Version: 7.x-2.x-dev » 7.x-2.2
Category: support » bug

Same problem here. Setting a variable through php evaluation on a "Add a variable" action works fine. However using an action of type "Execute custom PHP code" and setting the variable with @altavis 's code above doesn't work.

This affects the latest recommended version as well. Switching to Bug report to get some attention as I can't tell if it is a bug or a lack of documentation on the proper manner to change Provided variable through code.

mitchell’s picture

Title: How to set provided variable programatically » PHP Filter: 'Add a variable' text token does not work
Version: 7.x-2.2 » 7.x-2.x-dev
Priority: Normal » Major

> using an action of type "Execute custom PHP code" and setting the variable with @altavis 's code above doesn't work.
I think 'Add a variable' is the action we need to use for this, not 'Execute custom PHP code'.

I tried a couple variations of #1 and couldn't make this work either. This appears to be a common difficulty, so raising the priority.

mitchell’s picture

This appears to be a duplicate of #1231418: Provide access to variables to the PHP data processor. ..thinking

firfin’s picture

Dunno what you are thinking mitchell, but here are my thoughts :-)

I ran into this one a couple of times myself. Don't know if this warrants higher priority though.
But I agree with your assesment that this is a dupe of #1231418: Provide access to variables to the PHP data processor
Posted there asking confirmation.

mitchell’s picture

Status: Active » Closed (duplicate)

Thanks, firfin. :-)

Thinking was really learning more about RulesPHPEvaluator vs RulesPHPDataProcessor and scanning through the issue queue to find if anything else was being worked on around this.

I'm 95% sure that there's no more info to add and that I've marked the other open support request / feature request / bug reports as duplicates. So, now we can focus on fago's the plan to add this.

See #1231418: Provide access to variables to the PHP data processor.