Hello,
1. I have a created the subgrid "Asset Register" in the customer entity which is having the customer lookup.
2.In the contract entity i have added the "Asset Register " subgrid based on the customer selected in contract related to that customer ,only that record should be Associate to the subgrid "Asset Register" plaese any body suggest me. below is my code
namespace Asset_Register
{
public class Class1 : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
//Guid entref = Guid.Empty;
ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
Entity entity = (Entity)context.InputParameters["Target"];
//var contract = service.Retrieve(entity.LogicalName, entity.Id, new ColumnSet(true));
/*QueryExpression query1 = new QueryExpression("contract");
query1.Criteria.AddCondition("contractid", ConditionOperator.Equal, entity.Id);
query1.ColumnSet = new ColumnSet(true);
EntityCollection result1 = service.RetrieveMultiple(query1);
foreach (var updateamount1 in result1.Entities)
{*/
EntityReference entre = entity.GetAttributeValue<EntityReference>("customerid");
Guid entref = entre.Id;
QueryExpression query = new QueryExpression("new_updateamount");
query.Criteria.AddCondition("new_customerlookup", ConditionOperator.Equal, entref);
query.ColumnSet = new ColumnSet(true);
EntityCollection result = service.RetrieveMultiple(query);
foreach (var updateamount in result.Entities)
{
AssociateRequest teamToProfile = new AssociateRequest
{
Target = new EntityReference(updateamount.LogicalName, updateamount.Id),
RelatedEntities = new EntityReferenceCollection
{
new EntityReference("account", entref)
},
Relationship = new Relationship("new_account_new_updateamount_Customerlookup")
};
// Execute the request.
service.Execute(teamToProfile);
//Entity en = (Entity)context.InputParameters["Target"];
/*AssociateRequest assreq = new AssociateRequest();
assreq.Target = new EntityReference(updateamount.LogicalName, updateamount.Id);
assreq.RelatedEntities = new EntityReferenceCollection();
assreq.RelatedEntities.Add(new EntityReference("account", entref));
assreq.Relationship = new Relationship("contract_customer_accounts");
AssociateResponse assresponse = (AssociateResponse)service.Execute(assreq);*/
}
}
}
}
*This post is locked for comments