Score:0

How to use integer fetched from an Entity as an Entity ID?

ma flag

I have a rule component that is supposed to fetch an integer from a property of an entity named "Course" (ECK property). This property is not an entity reference but an integer. I use this property to set the number of Courses "cloned" on the "original course ID" once an entity of Course is "cloned". The cloning works but my component works ONLY IF I use it in my Views Entity VBO as an action. There I simply select a Course that has a valid [original-course-id] value and then I fire that component rule.

That works.

But the component does not work when it's integrated in the rule. Here's the structure:

Main rule: An entity has been flagged. (this works)
=> component 1 (inside this Main rule): clone the Course (this works)
=> component 2 (inside this component 1) DO:

  1. "fetch entity by ID" (the "original-course-id", from the clone i.e. [the-cloned-course:original-entity-id])
  2. "set data value": "the-fetched-course-id:total-course-bookings" new value "the-fetched-course-id:total-course-bookings", add an offset: 1.

So why is it working in my Views VBO but not in the rule itself where I need it.

When integrated in the Main Rule, the variables (parameters) are:

  1. flagging-user
  2. flagged-course

When integrated in the Component 1, the variables (parameters) are:

  1. the-fresh-course (the cloned Course)

What really happens in the integration of the rule is that when it fetches the entity by ID (original-course-id), it takes the Entity ID from the CLONE but not the ID from the property [the-original-course-id]. Why? I fetched it and my Views VBO confirms that.

Here's the code of that component 2:

{ "rules_upon_first_booking_update_the_original_course" : {
"LABEL" : "Upon First Booking Update the Original Course",
"PLUGIN" : "rule",
"OWNER" : "rules",
"TAGS" : [ "booking", "first booking", "original Course", "update", "updating" ],
"REQUIRES" : [ "rules" ],
"USES VARIABLES" : { "the_fresh_course" : { "label" : "The Fresh Course", "type" : "course" } },
"DO" : [
  { "entity_fetch" : {
      "USING" : { "type" : "course", "id" : [ "the-fresh-course:original-course-id" ] },
      "PROVIDE" : { "entity_fetched" : { "the_fetched_original_course" : "The Fetched Original Course" } }
    }
  },
  { "data_set" : {
      "data" : [ "the-fetched-original-course:total-course-bookings" ],
      "value" : {
        "select" : "the-fetched-original-course:total-course-bookings",
        "num_offset" : { "value" : "1" }
      }
    }
  }
]

} }

Who can help?

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.