RE: How to get parent record ID while adding a new record in n:n relationship
Hi,
when ever you create any N:N Relationship, then CRM DB will create one table with the name of Schema name of N:N Relationship.Based on that you need to retrieve GUID.
for example Account to Contact N:N Relationship is name is new_account_contact
Then I will retrieve record like
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity entity = (Entity)context.InputParameters["Target"];
using (var xrm = new XrmServiceContext(service))
{
var que =Xrm.new_account_contact.where(ac=>ac.accountid==entity.id).select(ca=>ca.contactId).FirstOrDefault();
}
}
Note : Here I am using Earlybind and added XRM file.
accountid and contactId are columns in new_account_contact table
Hope it Helps you
Thanks.