Hi Guys, I've got a problem. I have got 3 entities : Company, Campaign and Promotions. Company has a "One to Many" association with Campaign (Campaign_Company). Campaign has a "One to Many" association with Promotion(Promotion_Campaign). Company also has a "One to Many" association with Promotion (Promotion_Company). On the Promotion entity I create an eventhandler: Moment = After Event = Commit Microflow = ACr_PromotionSetCompany The ACr_PromotionSetCompany microflow basically gets Promotion as input, it then retreives the campaign by association. Then it retreives the Campaign's company by association. And then it changes the Promotion's Company to the retreived campaign's company. Upon creation of a Campaign, I've got a datagrid that shows all promotions linked to the campaign. On the Promotion_NewEdit form I wnat to display the promotions company. So when I click "New" on the datagrid, it obviuosly triggers the Eventhandler and in turn the Microflow. But this is where my problem is, the promotion company never gets set to the campaign's company. When I step through the microflow, Promotion >> Promotion_Campaign is empty. So it will never get the Company. What am I doing wrong here? Kind Regards Frikkie Chalmers Truworths South Africa
asked
Frikkie Chalmers
3 answers
5
Context is only set after the after create has fired. So retrieving the campaign via the promotion will return nothing. You can fix this by using a microflow button (which you call New) to call the Promotion_NewEdit form. Use the campaign as input (in microflow settings). In that microflow you can then retrieve the campaign's company and set the promotion company to that company. NOTE: drawback compared to the aftercreate is that this microflow only fires when you press that New button and not when a promotion is created in a different way (e.g. via a webservice). If you want to assure that it is always set, also check and set the company in a before commit.
answered
Frans Verschoor (FraternIT)
3
I think the ACr gets triggered before the association is set by the data grid.
You can avoid this whole situation by not using an after create but an microflow which properly instantiates the object and sets the association. In my humble opinion that is the preferred way to model such situations, and events should not be used for this (but that is a matter of taste).
answered
Michel Weststrate
0
Thank you very much for the clear and very quick response.
I went with Frans' answer and it is working.
Unfortunately, when I try to mark it as the correct answer, my browser(IE 6) crashes.