Hi,
Both entity are in a relation and field value is same for both entity.If i insert manually all field value in one entity field then the related entity field value auto populate through plugin.
*This post is locked for comments
Hi,
It will be better if you use quick view form.
Otherwise on update of entity write a plugin and get all the related entity and update.
Thanks
Hemant
Hi ,
At the time of registration a plugin i used: message type::-create and post operation
Can we use this code for creation entity field value.
Entity ee = new Entity("entity name");
service.Create(ee);
Depends on the relationship 1:1 or 1:N etc
If 1:1 and only update in 1 entity you can update with process.
The problem is if you update in either you can start looping although checking pre and post image will stop the plugin looping.
If 1:N use a plugin:
public class Update : IPlugin
{
public void Execute(IServiceProvider serviceProvider)
{
IPluginExecutionContext context =
(IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
var ServiceContext = new OrganizationServiceContext(service);
if (context.InputParameters.Contains("Target") && (context.InputParameters["Target"] is Entity))
{
Entity entity1 = (Entity)context.InputParameters["Target"];
Entity preContact = context.PreEntityImages["Image"];
Entity postContact = context.PostEntityImages["PostImage"];
string origfield = preContact.GetAttributeValue<string>("entity1field");
string difffield = postContact.GetAttributeValue<string>("entity1field");
if (origfield != difffield)
{
try
{
//Create query to get the related field
var res = from c in ServiceContext.CreateQuery("entity2")
where c["field"].Equals(entity1PK.Id)
select c;
foreach (var c in res)
{
Entity e = (Entity)c;
e["entity2field"] = difffield;
//ServiceContext.Attach(e);
ServiceContext.UpdateObject(e);
}
ServiceContext.SaveChanges();
throw new InvalidPluginExecutionException("An error occurred in the plug-in.");
}
catch (Exception ex)
{
throw new InvalidPluginExecutionException("An error occurred in the plug-in.", ex);
}
}
}
}
}
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156