Current filter:
                                You should refresh the page.
                                  • I would like to update a child record with an object selected from a dropdown on the parent.   Seems easy and can find several similar posts but nothing that works.   See the attached that gives a little more details into what I am trying to accomplish.

                                2 Solutions

                                Creation Date Importance Sort by

                                Hello,
                                 
                                Let me suggest an alternative approach. Based on my experience, storing the same information (the Order.ShipTo value) in several places (in the Order and OrderRelease classes) will lead to collisions and problems in the future. So I strongly recommend you avoid using this practice.
                                If I correctly understand, you wish to create a ShipPlan class that contains one property of the ShipTo type and should show all OrderRelease instances that relate to this ShipTo property.
                                To accomplish this task, I suggest that you create a non-persistent, non-associated collection of the OrderRelease classes in the ShipPlan class as shown here: Collection Properties in XPO and then filter this collection using the ShipPlan.ShipTo property.
                                You also don't need to store the ShipTo value in the OrderRelease class, you can get this value using an association between the OrderRelease and Order classes. I created a simple example based on your description that illustrates this approach in action. Please try it and let me know whether this approach meets your requirements.
                                 
                                Thanks,
                                Andrey T807002

                                • Customer82561 08.20.2019

                                  Thank you so much!  That is very close to what I want.    Thank you for your comment about: "storing the same information (the Order.ShipTo value) in several places (in the Order and OrderRelease classes) will lead to collisions and problems in the future. So I strongly recommend you avoid using this practice."

                                  Coming from an old ISAM database system, old habits die hard and I don't want to store duplicate data if I don't have to.
                                  The only thing different from your example is I want to allow the user to select the releases that they want to ship.   They wont all ship.   So making it persistent works better.   I tried changing my code to this:

                                  [DataSourceCriteria("Order.CustomerShipTo = '@This.CustomerShipTo' && Status == 0")]
                                  [Association("OrderAsp-OrderReleases")]

                                  Now when I choose the LINK button it brings up a list of the releases from the proper ship to so I can select the.    Changing to a different shipto and then choosing link, gives me a different list to choose from.    Is this the proper way to accomplish this?

                                  Thanks again

                                • Andrey K (DevExpress Support) 08.21.2019

                                  Hello,
                                   
                                  In case you need to filter a list for a lookup editor or for the Link/Unlink popup, the use of the DataSourceCriteria attribute is a correct approach. The only note is that it is better to use an object's key value in the criterion instead of the object itself. For example: Order.CustomerShipTo.Oid = '@This.CustomerShipTo.Oid'
                                  Let me know in case of any further questions.
                                   
                                  Thanks,
                                  Andrey

                                • Customer82561 08.22.2019

                                  That is perfect, thanks so much.

                                • Andrey K (DevExpress Support) 08.23.2019

                                  I am happy to hear that everything works well. The solution took a bit of time to put together, so I appreciate your patience.
                                  We are always here to help. Let me know if I can be of further assistance.
                                   
                                  Thanks,
                                  Andrey

                                Hi,

                                Since you have a master-detail relationship between the Order and OrderRelease classes, the OrderRelease class has a reference property to its parent Order object. So, when a new OrderRelease object is added to the Order OrderRelease collection, the property setter with the parent Order object is called. You can put your logic in the property setter. The "Initialize a Property of a Child Object with a Value Taken from Master Object" case from the How to: Initialize Business Objects with Default Property Values in XPO article should be suitable for you.

                                The same happens when the Order ShipTo1 property is updated. In the property setter, you can traverse through the Order OrderRelease collection and update its OrderRelease objects.

                                Show all comments
                                • Customer82561 08.19.2019

                                  Thanks Gosha, I read that article again and managed to get the Child updated from the master when new and changing.   Thank you!   I will attempt the traversal of the releases next and report back.

                                • Gosha (DevExpress Support) 08.19.2019

                                  You are welcome!

                                • Customer82561 08.19.2019

                                  Gosha, I tried the code below in the parent class and it does not give me any errors, but it also does not actually change the data.   When debugging I see it processing the statement on all the child records - but no update.   Also, what is the best way to only change the release when the order.CustomerShipTo changes?

                                  [C#]
                                  protected override void OnSaving() { base.OnSaving(); foreach (OrderRelease orderRelease in OrderReleases) orderRelease.CustomerShipTo = CustomerShipTo; }
                                • Customer82561 08.19.2019

                                  Sorry Added the orderRelease.save() and the save works.
                                  Still trying to determine if the CustomerShipTo changed before looping through the collection.

                                • Anatol (DevExpress Support) 08.19.2019

                                  See an example of how to implement this business logic only when the dependent properties are changed here: How to: Calculate a Property Value Based on Values from a Detail Collection.

                                  Sorry Added the orderRelease.save() and the save works.

                                  Is this an XAF application? If so, it is unclear why setting the CustomerShipTo property was insufficient. Please ensure that this property is implemented through the SetPropertyValue method, as shown in the following topic: PropertyChanged Event in Business Classes.
                                  If this is a non-XAF application, or you are creating the Session instance to load these objects in your own code, you can use the UnitOfWork class instead of calling the Save method:
                                  Unit of Work
                                  Using Transactions

                                • Customer82561 08.19.2019

                                  Yes this is an XAF application.    I think you may be confused as to what I am trying to do.

                                  I have a Parent(Order) that has a children(Releases).   It parent has a CustomerShipTo object on it.

                                  Next we have a Parent (Shipment) where we select a CustomerShipTo.    Then we LINK to the releases.    I wanted to see ONLY those releases for the proper customer ship to, so I added the CustomerShipTo to the RELEASES table above.    If I can access the PARENT order/CustomerShipTo from the releases I am linking it would negate this whole process!

                                  But because I am thinking I need the customerShipTo on the release to filter the link, I have to update the release with the parents CusotmerShipTo when it's created - But if the Parent gets updated and the CustomerShipTo changes, then I have to update all the Child releases with the new CustomerShipTo.

                                  When updating the Children I use the below code without the SetPropertyValue Method and it works fine when I save the record.

                                  [C#]
                                  public override void AfterConstruction() { base.AfterConstruction(); LastUpdate = DateTime.Now; LastUpdateBy = "Randy"; // GetCurrentUser(); Status = ReleaseStatus.Open; } protected override void OnSaving() { base.OnSaving(); LastUpdate = DateTime.Now; LastUpdateBy = "Randy"; // GetCurrentUser(); }

                                  When doing the same thing for the parent class when attempting to save while looping through the releases it does not save unless I use the save()

                                  [C#]
                                  protected override void OnSaving() { base.OnSaving(); foreach (OrderRelease orderRelease in OrderReleases) { orderRelease.CustomerShipTo = CustomerShipTo; orderRelease.Save(); } }

                                  Does this make any sense?