Лучший отвечающий
create task on resolve of case using plugin

Вопрос
-
how to create a task on resolving a case in ms crm using plugin.21 мая 2015 г. 6:37
Ответы
-
Amy,
Incident Resolution is an entity. You are trying to attach a not to an incident resolution entity. You need to attach the note to the incedent entity. You should retrieve the incident first and work you way down to create the note with the incident:
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { Entity entity = (Entity)context.InputParameters["Target"]; if(!entity.containsKey("incidentid")) return; Entity TheRealIncidentAndNotTheIncidentResolutionRecord = service.Retrieve("incident", ((EntityReference)entity["incidentid"]).Id, new ColumnSet(true)); ... }
- Помечено в качестве ответа Amy.4 28 мая 2015 г. 6:14
22 мая 2015 г. 10:43 -
Hi,
Your plugin is not working, because you creating a new entity:
Entity Note = new Entity("annotation");
and then trying to change entity attributes:
Note["notetext"] = "Hello!! Created a note"; Note["ObjectId"] = new EntityReference(context.PrimaryEntityName, new Guid(context.PrimaryEntityId.ToString())); Note["Subject"] = "Your Title";
Witch are not exits in your entity.
You should use
Note.Attributes.Add()
function to add an attribute
https://msdn.microsoft.com/en-us/library/gg307396.aspx
For example:
instead of:
Note["notetext"] = "Hello!! Created a note";
You should write:
Note.Attributes.Add(new KeyValuePair<string, object>("notetext", "Hello!! Created a note"));
22 мая 2015 г. 10:52
Все ответы
-
Hi,
To create an Entity in plugin you can use:
service.create();
More info: https://msdn.microsoft.com/en-us/library/gg594416.aspx
21 мая 2015 г. 12:43 -
-
Hi Jochen , i have been using the below code but unable to create the note.. any suggestions on this if i need to change anything... in the sdk i have registered the plugin on create of "incident resolution"
My aim is to create a note whenever a case is resolved....
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) { Entity entity = (Entity)context.InputParameters["Target"]; if (((OptionSetValue)entity.Attributes["statuscode"]).Value == 5) //Status Reason = Problem solved { Entity Note = new Entity("annotation"); Note["notetext"] = "Hello!! Created a note"; Note["ObjectId"] = new EntityReference(context.PrimaryEntityName, new Guid(context.PrimaryEntityId.ToString())); Note["Subject"] = "Your Title"; Guid annotationId = service.Create(Note);
22 мая 2015 г. 10:23 -
Amy,
Incident Resolution is an entity. You are trying to attach a not to an incident resolution entity. You need to attach the note to the incedent entity. You should retrieve the incident first and work you way down to create the note with the incident:
if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { Entity entity = (Entity)context.InputParameters["Target"]; if(!entity.containsKey("incidentid")) return; Entity TheRealIncidentAndNotTheIncidentResolutionRecord = service.Retrieve("incident", ((EntityReference)entity["incidentid"]).Id, new ColumnSet(true)); ... }
- Помечено в качестве ответа Amy.4 28 мая 2015 г. 6:14
22 мая 2015 г. 10:43 -
Hi,
Your plugin is not working, because you creating a new entity:
Entity Note = new Entity("annotation");
and then trying to change entity attributes:
Note["notetext"] = "Hello!! Created a note"; Note["ObjectId"] = new EntityReference(context.PrimaryEntityName, new Guid(context.PrimaryEntityId.ToString())); Note["Subject"] = "Your Title";
Witch are not exits in your entity.
You should use
Note.Attributes.Add()
function to add an attribute
https://msdn.microsoft.com/en-us/library/gg307396.aspx
For example:
instead of:
Note["notetext"] = "Hello!! Created a note";
You should write:
Note.Attributes.Add(new KeyValuePair<string, object>("notetext", "Hello!! Created a note"));
22 мая 2015 г. 10:52 -
Thank you for the response Jochen and Xjomanx .. also can i know on which meesage and entity(incident or incidentresolution) this needs to be registered in sdk..??22 мая 2015 г. 11:35
-
Incidentresolution and get the incident from the target like I mentioned above.
Kind Regards
22 мая 2015 г. 11:38