Thanks for the rules module, I could not live without it.

Is there any way to use a rules action to set an entity reference field to Null / Empty?

Any help would be hugely appreciated.

Comments

kingswoodute’s picture

Ahh, got it.

If anyone else runs into a problem doing this. The issue I had was that I was leaving the data selector blank and it was giving me an error message. BUT If you switch to the direct input mode and leave it blank it will work.

Have a great one.

geek-merlin’s picture

Issue summary: View changes
Status: Active » Fixed

So fixed.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

mkostir’s picture

Status: Closed (fixed) » Needs review

I'd like to re-open this thread, as switching to direct input mode isn't a solution.

I am having the same issue when setting entity reference. However I can't use this workaround as the value being set (TARGET) is a value taken from another field (SOURCE)- hence changed dynamically.

As long as Source has any value, everything works as it is supposed to. But as soon as SOURCE is empty, it will raise this error:

Unable to modify data "fetched-from-entity:field-account-ref": Invalid data value given. Be sure it matches the required data type and format.

Any advice would be warmly welcome

geek-merlin’s picture

@mkostir: it will help if you can write an idiot-proof step by step guide how to reproduce this.

crutch’s picture

I'll try, because this worked for me when using conditional fields that do not reset radios. This won't work with required fields though specifically when using conditional fields that are set as required.

Event

After updating existing content type of "Course"

Condition

+ Entity has field
Parameter: Entity: [node], Field: field_select_office_location (this is the entity reference field)

+ Data comparison
Parameter: Data to compare: [node:field-location-type], Data value: School Location (data value could be School Location or Office Location but when School location is chosen then the conditional field for Office should be set to null, otherwise a mis-clicked radio under Office will be remain selected and then show 2 locations on the node)

Actions
+ Set a data value
Parameter: Data: [node:field-select-office-location]

Data--- Selected data: node:field-select-office-location
Value---
The new value to set for the specified data.
Data selector = blank/empty do not enter anything

In my case I didn't have to switch to direct input mode and it saved with no errors and sets the value to null as expected.

tr’s picture

Version: 7.x-2.2 » 7.x-2.x-dev
Status: Needs review » Active

There is no patch, so "Needs review" is the wrong status.

tr’s picture

Version: 7.x-2.x-dev » 8.x-3.x-dev
crutch’s picture

StatusFileSize
new45.55 KB
new125.53 KB
new119.97 KB
new152.4 KB
new77.33 KB