Help with accessing data in rules..

Events happening in the community are now at Drupal community events on www.drupal.org.
wipeout_dude's picture

Hi,

I am having a hard time getting the information I need into a rule in order to perform a calculation.. Hopefully I can explain it well and someone has a suggestion..

I have three content types.. For simplicity we will call them "A", "B" and "C"..

"A" is the main one and "B" and "C" each have a node reference back to "A"..

The rule I am creating needs to run on the creation or update of "B".. When its run I need to pull in a value from a field on "A" and "C".. I have been able to get the value out of "A" through the reference.. What I can't work out is how to look up and get the value out of "B"..

I hope that makes sense..

Anyone have any suggestions?

Thanks..

Comments

I learned that Rules often

Bob Newby's picture

I learned that Rules often needs a condition declaring the existence of each field you want to utilize, so this may be an issue for you.

In psuedo code:

  • Condition
    -- If A has field field_xyz
    --- Condition
    ---- If B has field field_abc
    etc.
    ----- Action 1
    ----- Action 2
    etc.

Can't get there..

wipeout_dude's picture

Hi Bob..

Thanks for the reply..

Unfortunately I can't get to the field in the rule because it's in content type C that references (node reference) content type A and I am triggering on changes to content type B which also references content type A but doesn't have any direct reference to content type C..

So graphically the references are "B" --> "A" <-- "C"

There is no way I can see to connect a field through a reference and then a back-reference from the referenced node to another node..

Since posting the question is seems that even if the references were "B" --> "A" --> "C" rules probably wouldn't be able to get there because it would have to go through two references..

Seems like the only way would be to create a reference directly from "B" to "C" but that will become very messy to try and maintain when staff are creating new entries..

Maybe I am going to have to work out how to look up the value of the field with some PHP code in the rule but I am not a coder and have heard this is a bad idea so was trying to avoid that.. :)

Fetch entity by property

zhangtaihao's picture

You could always try to fetch a referenced entity by the entity reference field. If that doesn't work, you could also try plugging a view (using Views Rules) into the rule to get the referenced entity for the actions.

This is a good suggestion.

Bob Newby's picture

This is a good suggestion.

patch to ctools

kvanderw's picture

I know that we have solved that here.
Had the same type of problem.

Ctools has a 'reverse' lookup that has a bug in it.

That bug has been squashed with the help of EclipseGc a few weeks back.
His attention is a bit difficult to get as he has an upcoming deadline on the 18th for his initiative.

It has NOT been patched and applied back yet.
I will bug my programmer to get that posted for you.

Rules is a bit over me at this point, so I'm not sure if we also did some internal rules work to get it operational. I'll check further for you.

Kurt Vanderwater
Drupal made Easy

Use the rules and execute the php code too..

rakesh.gectcr's picture

Any way you are able to get the values from 'A' , What i understand, In the rule that after creating or updating the "B" you want to get the values from "A" and "C".?

If it is ..

Create the rule and get the values from "A".

Next action put the PHP execute and write the query and get the entity_id value of "C" which having the node ref of "A".

then give that entity_id to entity load function or use the node_load function.

you looking for the coding help share me the details. i can code for you ASAP.

Rakesh James