locked
add a note to case while resolving it RRS feed

  • Question

  • I want to create and add a note to the case while resolving the case using plugin. How can i do this.

    I have registered this on create of incidentresolution in plugin registration tool.

    Iam using the below code but the note is not being added to case after resolving it

            public void Execute(IServiceProvider serviceProvider)
            {
                ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));
                IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
    
                IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
    
                // Create service with context of current user
                IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
                tracingService.Trace("input parameters");
    
                if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity)
                {
                    //create entity context
                    Entity entity = (Entity)context.InputParameters["Target"];
    
                    if (entity.LogicalName != "incident") { return; }
    
                    if (((OptionSetValue)entity.Attributes["statuscode"]).Value == 5)
                    {
                        Entity Note = new Entity("annotation");
                        //The comment you want to write to this specific case
                        Note["notetext"] = "Hello!! Created a note";
                        //The “ObjetID” is the ID if the record you want to assign the note to it (Note can be assigned to many type of entities not just case)
                        //”incident” is the logical name of the “Case” Entity and IncidentID is the GUID of the record.
                        Note["ObjectId"] = new EntityReference(context.PrimaryEntityName, new Guid(context.PrimaryEntityId.ToString()));
                        //Set the title of the “Note”
                        Note["Subject"] = "Your Title";
                        //Create the record
                        service.Create(Note); 

    Friday, May 22, 2015 9:19 AM

All replies