1

i've an import module built with Rules which imports my users. An user can have one or many conventions. I manage these conventions with taxonomy. Conventions are store in my user fields, 'Number of values' under Field settings as 'Unlimited' My point is, i cannot add many conventions to an user, only the last convention keep in store. This is how i did:

{ "rules_updatepartenaireslistbatch" : {
    "LABEL" : "UpdatePartenairesListBatch",
    "PLUGIN" : "action set",
    "OWNER" : "rules",
    "REQUIRES" : [ "rules", "wsclient", "rules_conditional" ],
    "ACTION SET" : [
      { "data_create" : {
          "USING" : {
            "type" : "wsclient_ws_applicam_partenaire_FiltresPartenaire",
            "param_codePartenaire" : [ "" ],
            "param_complet" : 0,
            "param_conventions" : [ "" ],
            "param_raisonSociale" : [ "" ],
            "param_statutCode" : [ "" ],
            "param_typesAttribut" : [ "" ],
            "param_ville" : [ "" ],
            "param_top" : "20"
          },
          "PROVIDE" : { "data_created" : { "data_filtrepartenaire" : "Created data" } }
        }
      },
      { "data_create" : {
          "USING" : {
            "type" : "wsclient_ws_applicam_partenaire_GetListePartenaires",
            "param_numSite" : "1058",
            "param_filtres" : [ "data-filtrepartenaire" ]
          },
          "PROVIDE" : { "data_created" : { "data_getlistpartenaire" : "Created data" } }
        }
      },
      { "wsclient_ws_applicam_partenaire_GetListePartenaires" : {
          "USING" : { "param_parameters" : [ "data-getlistpartenaire" ] },
          "PROVIDE" : { "result" : { "result_list_partenaire" : "GetListePartenairesResponse" } }
        }
      },
      { "LOOP" : {
          "USING" : { "list" : [ "result-list-partenaire:GetListePartenairesResult" ] },
          "ITEM" : { "partenaire_item" : "Current list item" },
          "DO" : [
            { "data_convert" : {
                "USING" : { "type" : "text", "value" : [ "partenaire-item:id" ] },
                "PROVIDE" : { "conversion_result" : { "string_id" : "Conversion result" } }
              }
            },
            { "entity_query" : {
                "USING" : {
                  "type" : "user",
                  "property" : "name",
                  "value" : "PART_[string-id:value]",
                  "limit" : "1"
                },
                "PROVIDE" : { "entity_fetched" : { "part_fetched" : "Fetched entity" } }
              }
            },
            { "CONDITIONAL" : [
                {
                  "IF" : { "data_is_empty" : { "data" : [ "part-fetched:0" ] } },
                  "DO" : [
                    { "entity_create" : {
                        "USING" : {
                          "type" : "user",
                          "param_name" : "PART_[string-id:value]",
                          "param_mail" : "PART_[string-id:value]@here.invalid"
                        },
                        "PROVIDE" : { "entity_created" : { "entity_part" : "Created entity" } }
                      }
                    },
                    { "entity_save" : { "data" : [ "entity-part" ], "immediate" : 1 } },
                    { "user_add_role" : { "account" : [ "entity-part" ], "roles" : { "value" : { "5" : "5" } } } },
                    { "user_unblock" : { "account" : [ "entity-part" ] } }
                  ]
                },
                { "ELSE" : [
                    { "variable_add" : {
                        "USING" : { "type" : "user", "value" : [ "part-fetched:0" ] },
                        "PROVIDE" : { "variable_added" : { "entity_part" : "Added variable" } }
                      }
                    }
                  ]
                }
              ]
            },
            { "LOOP" : {
                "USING" : { "list" : [ "partenaire-item:conventions" ] },
                "ITEM" : { "convention" : "Current list item" },
                "DO" : [
                  { "entity_query" : {
                      "USING" : {
                        "type" : "taxonomy_term",
                        "property" : "name",
                        "value" : [ "convention:libelle" ],
                        "limit" : "1"
                      },
                      "PROVIDE" : { "entity_fetched" : { "entity_fetched" : "Fetched entity" } }
                    }
                  },
                  { "CONDITIONAL" : [
                      {
                        "IF" : { "data_is_empty" : { "data" : [ "entity-fetched" ] } },
                        "DO" : [
                          { "entity_create" : {
                              "USING" : {
                                "type" : "taxonomy_term",
                                "param_name" : [ "convention:libelle" ],
                                "param_vocabulary" : "conventions"
                              },
                              "PROVIDE" : { "entity_created" : { "entity_created" : "Created entity" } }
                            }
                          },
                          { "entity_save" : { "data" : [ "entity-created" ], "immediate" : 1 } }
                        ]
                      },
                      { "ELSE" : [
                          { "variable_add" : {
                              "USING" : { "type" : "taxonomy_term", "value" : [ "entity-fetched:0" ] },
                              "PROVIDE" : { "variable_added" : { "entity_created" : "Added variable" } }
                            }
                          }
                        ]
                      }
                    ]
                  },
                  { "data_set" : {
                      "data" : [ "entity-part:field-conventions:0" ],
                      "value" : [ "entity-created" ]
                    }
                  },
                  { "entity_save" : { "data" : [ "entity-part" ], "immediate" : 1 } },
                  { "drupal_message" : { "message" : [ "entity-created:name" ] } }
                ]
              }
            },
            { "component_rules_update_partenaire" : { "user" : [ "entity-part" ], "partenaire" : [ "partenaire-item" ] } }
          ]
        }
      }
    ]
  }
}

The aim is simple. - I get all users from a webservice - I do a loop on users - I loop on user conventions - if convention doesn't exist as taxonomy term, i create it - else, I had the taxonomy term in a variable - I use a "set_data" to add the convention to the user

Ex: one of my user has "SPORT" and "CINEMA" in conventions. Only "CINEMA" is stored.

  • 2
    What's a "boucle"? In English that's a yarn with a looped or curled ply, or fabric woven from this yarn. Perhaps not what you meant :) – Clive Sep 29 '14 at 10:01
  • please apologize, i've fixed :) – billyJoe Sep 29 '14 at 10:02
1

Check if the Taxonomy user field (Convention) allows multiple values.

  1. Go to Admin > Configuration > People > Account Settings > Manage Fields
  2. Edit the Term Reference field (in your case, Convention)
  3. Set 'Number of values' under Field settings as 'Unlimited' or 2 or as desired
  4. Save
  5. Execute the rule and check

Hope this helps.

Regards, Supriya Rajgopal

  • 1
    Thank for your reponse but unfortunately, i've already applied this configuration :( – billyJoe Sep 29 '14 at 11:00
  • 1
    @billyJoe add this info to your question, or emphase it more if it's already there, please. I couldn't see it, and Supriya's answer is most obvious thing to tell when somebody does not know you already checked it. – Mołot Sep 29 '14 at 11:05
  • i've added this information to my initial post. – billyJoe Sep 29 '14 at 11:30
0

Resolved ! I had simply to replace the data set by "Add an item to a list". So i had each convention in my loop in the user's convention list.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.