create new entity with fields record resolved by(lookup to syster user), record resolved on (date and time), by using plugin fill this data on status change to inactive.
Create new entity with fields record resolved by(lookup to system user), record resolved on (date and time), by using plugin fill this data on status change to inactive.
Step 1: Create a New Entity as ResolveRecord.
Step 2: Create fields RecordResolved by (lookup with system user) and RecordResolved on (Date and Time).
Next add the status field which name as statecode (like schema name).
Step 3: Create a Plugin according to the Scenario .
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.Xrm.Sdk;
namespace aRepoTrack
{
public class RepoTrack : 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);
ITracingService tracing = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
//effizz_recordresolvedby,effizz_recordresolvedon,statecode,effizz_name
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
{
tracing.Trace("print one");
Entity newEntity = (Entity)context.InputParameters["Target"];
Guid userID = context.InitiatingUserId;
OptionSetValue status = newEntity.GetAttributeValue<OptionSetValue>("statecode");
if (status.Value == 1)
{
tracing.Trace("print two");
newEntity["effizz_name"] = "user"; //+ DateTime.UtcNow;
newEntity["effizz_recordresolvedby"] = new EntityReference("systemuser", userID);
newEntity["effizz_recordresolvedon"] = DateTime.UtcNow;
}
if (context.Depth == 1)
{
tracing.Trace("print three");
service.Update(newEntity);
}
}
}
}
}
.png)




Comments
Post a Comment