Hi,
I have a requirement, where after updating the status of the record from open to complete, modified on date should be same as before the status update . We tried it using the plugin at the pre Operation stage and registered Pre-image to get the modified on date before status update. The date we got from preimage has been set to the modifiedon date to the target entity form the plugin context.
modified on date is not updating with the modified on date that obtained from the preimage, where it is updating with the current date&time when status is updated. When I debugged the code it's showing that preimage modifiedon date is getting passed to the "activity["modifiedon"]".we have checked with the other plugin if any plugin is getting triggered after status updated, there are no plugins or other activities are getting triggered or updating the entity as we checked in the audit history. In audit history it's showing status update information and no other field is getting updated after status update.
Overwriting modifiedon date is working and reflecting for other fields update except status update.
Can one help me regarding this issue, why overriding modifiedon on status change is not working?
Below is the code that we are using for overriding the modifiedon date at pre-operation stage and it is working for rest of the fields other than status field. If I am updating name field when the time is X the modifiedon contains y time, after updating the name field the modified on time is beign overwritten with the y time.
public void Execute(IServiceProvider serviceProvider)
{
try
{
IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
IOrganizationServiceFactory servicefactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
IOrganizationService service = servicefactory.CreateOrganizationService(context.InitiatingUserId);
ITracingService trace = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
Entity activity = (Entity)context.InputParameters["Target"];
Entity preActivity = (Entity)context.PreEntityImages["PreActivity"];
DateTime modifiedOnfromPreImage = preActivity.GetAttributeValue<DateTime>("modifiedon");
if ( activity.Attributes.Contains("statecode"))
{
int status = activity.Attributes.Contains("statecode") ? ((OptionSetValue)activity.Attributes["statecode"]).Value : 0;
if (status == 1) //complete
{
activity["modifiedon"] = modifiedOnfromPreImage;
}
}
}
else
{
return;
}
}
catch (Exception)
{
throw;
}
}
I don't know your code and the logic behind it, but if you are updating a record when the time is X the modifiedon will contain X, if the time is Y the modified on will contain Y, you can't modify in Y time and put X time.
Thank you Preite
But When we check for all other fields which are available in entity modifiedon date is being overwritten with the plugin. When we check for status field update it is not getting overwritten.
modifiedon is an internal field, every time the record is updated the date changes and you cannot set a custom value inside it.
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... 290,524 Super User 2024 Season 2
Martin Dráb 228,469 Most Valuable Professional
nmaenpaa 101,148