问题
I have two different custom entities. The first one (payment) I create manually using a form. When the payment is created it executes a plugin that will create one or more vouchers. The plugin creates the voucher without a problem. The problem is when I go to the payment and click on vouchers, I don't see the voucher I just created listed. If I go look at all the vouchers I can see the one I just created. There is a 1 to many relationship from payment to voucher. What do I need to do in my plugin for the entities to be related?
Thanks
回答1:
Sounds like you just haven't setup the relationship back to the triggering payment when you create the voucher.
Given the 1:N relationship and since you're creating the voucher in the context of a payment plugin you can set the lookup on the voucher to the payment for which the plugin is currently executing (target).
new_voucher.new_paymentid = new EntityReference(...);
new_paymentid
is the lookup attribute on voucher (obviously it'll be called something else in your case). For the EntityReference
you'll need to define the EntityName and Id of the product, which you can read from the target.
来源:https://stackoverflow.com/questions/15510730/dynamics-crm-2011-how-to-relate-two-different-entities