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);

                }

            }

        }

    }

}

Step 4: Now Register assembly and Register a Step with Update.


Step 5: Check the Changes according to scenarios by update the name field.




Comments

Popular posts from this blog

If any case created, then check for the same user how many cases are created with in 30 days, if more than 2 and less than 5 send a mail to team lead, if more than 5 and less than 9 then send a mail to manager using power automate.

Create approve & reject ribbon buttons, once click on approve it should change the status field to approve.If clicked on reject it should change to Reject. Based on status field change trigger work flow to send a email to stating request is approved/Rejected.

How to get and set values in plugins?