Gary
Gary

Reputation: 1774

Dynamics CRM 2011 - How to relate two different entities

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

Upvotes: 0

Views: 409

Answers (1)

Darren Lewis
Darren Lewis

Reputation: 8488

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.

Upvotes: 3

Related Questions