7 – Using computed field value in Rules

Anyone running into this recently, I found a work around.

I used “Entity has field” as a condition on the Computed Field Value.

I then used the “Add a variable” action to add a text value of the Computed Field as a variable.

Then added a “Convert Data Type” action to turn the value into an integer.

I could then use “Set a data value” as normal.

Here is an export of my rule (for a different use case), but still setting Computed Field values as a Variable…

{ "rules_set_default_remaining_balance" : {
    "LABEL" : "Set Default Remaining Balance",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : ( "rules", "entityform" ),
    "ON" : { "entityform_insert" : () },
    "IF" : (
      { "entity_has_field" : { "entity" : ( "entityform" ), "field" : "field_total_price" } },
      { "entity_has_field" : { "entity" : ( "entityform" ), "field" : "field_remaining_balance" } },
      { "data_is_empty" : { "data" : ( "entityform:field-remaining-balance" ) } }
    ),
    "DO" : (
      { "variable_add" : {
          "USING" : { "type" : "text", "value" : ( "entityform:field-total-price" ) },
          "PROVIDE" : { "variable_added" : { "variable_total_price" : "Total Price" } }
        }
      },
      { "data_convert" : {
          "USING" : { "type" : "integer", "value" : ( "variable-total-price" ) },
          "PROVIDE" : { "conversion_result" : { "conversion_result" : "Conversion result" } }
        }
      },
      { "data_set" : {
          "data" : ( "entityform:field-remaining-balance" ),
          "value" : ( "conversion-result" )
        }
      }
    )
  }
}

In the example above, the field “Total Balance” is being Computed.