0

For the last couple of days I've been reading different solutions on forums how to achieve this but it looks like I'm missing something. Any thoughts on how to solve this would be really appreciated.

I have content type "report" that is made of collection field "proba". That collection field have another collection field inside named "detalji tabele". Inside that collection field ("detalji tabele") there are 2 groups with multiple fields inside (group "values" and group "control values").

One field group ("values") are filled by "admin" user roles and another field group ("control values") are filled by "controlor" user roles. This collection field "detalji tabele" can be added unlimited number of times inside one node.

First, users with 'admin user roles' are entering their data into 'values' field group, after that users with 'controlor roles' are entering their part of information in 'control values' group. All data from collection field are displayed through tables.

So I need to achieve following rule:

When users with "controlor roles" update "report" content type I need to compare values of two fields inside collection field "detalji tabele" that can be added unlimited number of times. One belongs to "values" group, and second field belongs to "control values" group. If they have same value then I need to set value in field name "procjena-odstupanja-tekst" or Semaphore. "Semaphore" is "text list" field inside "control values" group and if two compared fields have same value "semaphore" will be set to "OK".

I need to loop over those two fields inside collection field but I have manage to do it only on second collection field inside a node.

Here is my rule:

{ "rules_semafor_proba" : {
    "LABEL" : "semafor proba",
    "PLUGIN" : "reaction rule",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "rules_conditional", "field_collection" ],
    "ON" : {
      "node_update--izvje_taj_kontrolni" : { "bundle" : "izvje_taj_kontrolni" },
      "field_collection_item_update" : []
    },
    "IF" : [
      { "user_has_role" : {
          "account" : [ "site:current-user" ],
          "roles" : { "value" : { "5" : "5" } }
        }
      },
      { "entity_has_field" : {
          "entity" : [ "node:field-proba:1:field-detalji-tabele:1" ],
          "field" : "field_ik_dimenzija_na_crtezu"
        }
      },
      { "entity_has_field" : {
          "entity" : [ "node:field-proba:1:field-detalji-tabele:1" ],
          "field" : "field_izmjerena_dimenzij_kontrol"
        }
      }
    ],
    "DO" : [
      { "LOOP" : {
          "USING" : { "list" : [ "node:field-proba:1:field-detalji-tabele" ] },
          "ITEM" : { "list_item" : "Current list item" },
          "DO" : [
            { "CONDITIONAL" : [
                {
                  "IF" : { "data_is" : {
                      "data" : [
                        "node:field-proba:1:field-detalji-tabele:1:field-izmjerena-dimenzij-kontrol"
                      ],
                      "value" : [
                        "node:field-proba:1:field-detalji-tabele:1:field-ik-dimenzija-na-crtezu"
                      ]
                    }
                  },
                  "DO" : [
                    { "data_set" : {
                        "data" : [ "list-item:field-procjena-odstupanja-tekst" ],
                        "value" : "1 "
                      }
                    }
                  ]
                }
              ]
            }
          ]
        }
      }
    ]
  }
}

Here is also an image of my results (image attached). In this table 'Zadana vrijednost' equals [field-izmjerena-dimenzij-kontrol], and 'Stvarna vrijednost' equals [field-ik-dimenzija-na-crtezu]. When those two fields have same value then field procjena-odstupanja-tekst is set to 'U REDU' (OK).

But it works only with second field collection. First and third (and forth and fifth etc.) do not change when I edit them.

Results

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.