Hi, guys! Can anybody help me, please.
In my company, we use Case entity, and Service Activities regarding to case. When we save Service Activities, we want just to save them (and not Mark complete!), and in that moment, they must be in status Active. We use button Save for that.
Ok, but now, the problem is, because we have dialog for resolving case, and in that moment, when case is resolved, we want ALL service activites to change status (statuscode) to complete.
So, I was wondering if it's possible to add fetchxml to do foreach looping for that case and SET statuses for service activities to complite? I don't know if fetchxml can only filter data, or it can also SET values?
I've written fetchxml for filtering, but now I don't now how to add foreach loop for setting values and is that even posible?
If it's not possible, can you please tell me another way of doing that. I must implement it in dialog!
Here is my query:
<fetch version="1.0" output-format="xml-platform" mapping="logical" distinct="false">
<entity name="activitypointer">
<attribute name="activitytypecode" />
<attribute name="subject" />
<attribute name="statecode" />
<attribute name="prioritycode" />
<attribute name="modifiedon" />
<attribute name="activityid" />
<attribute name="instancetypecode" />
<attribute name="community" />
<order attribute="modifiedon" descending="false" />
<filter type="and">
<condition attribute="activitytypecode" operator="in">
<value>4214</value>
</condition>
<condition attribute="statecode" operator="ne" value="Variable1" />
</filter>
<link-entity name="incident" from="incidentid" to="regardingobjectid" alias="bd">
<filter type="and">
<condition attribute="ticketnumber" operator="eq" value="Variable2" />
</filter>
</link-entity>
</entity>
</fetch>
*This post is locked for comments
Hi Goutam,
The problem is, because you cannot resolve case if there are service activities with status active. So it's not possible to trigger plugin after case change status. Service acitivities must be completed before case is closed (but it is desirable on dialog for resolving, step before case is closed).
Another thing is that I'm not familiar with CRM plugins, so I'm looking for solution with javasctipt or fetchxml, if it's possible :).
Here is sample code -
public class CaseResolution : IPlugin { 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)); IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId); if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity) { //create entity context Entity entity = (Entity)context.InputParameters["Target"]; if (entity.LogicalName != "incidentresolution") return; try { if (entity.Contains("incidentid")) { var caseId = ((EntityReference)entity["incidentid"]).Id; // Retrieve the Activities and update the status here } } catch (Exception ex) { throw new InvalidPluginExecutionException(ex.Message); } } } }
Hi Marina,
You should write a plugin which will register create message of incidentresolution entity which will fire from resolve case dialog when you change the case status , when case got resolved , write the logic to retrieve service activity using fetch XML and iterate through loop and update the activity status.
Hope this helps.
Sir, thank you for your reply.
I'm not sure if I understand you where to implement that plugin? Is that as a custom step in dialog? Can you send me a link or an example how to do that?
Thank you very much!
Sir, thank you for your reply!
Yes, I know that it's not possible to resolve case it has open activities. But I have dialog for resolving case, and in that dialog, I want to implement step where I would complete all activities. And than after that, in next step I can resolve case.
I have this fetchxml for filtering service activities. I am wondering now if I can implement foreach loop in fetchxml that will update Service activities?
For this requirement I more prefer using plugin to solve this because in plugin we can have transaction scope (if one got error, then all will be rollback).
So basically you just need to create new attribute (usually I create text attribute because if I have multiple business logic, I can just use this attribute).
For instance on Case entity I will create new_operation(text).
Then when on your dialog, I will update this case.new_operation = "resolved all" or something.
Then I will create new business logic on the plugin:
if(context.Input.Contains("new_operation") && conte.Input["new_operation"] == "resolved all")
{
//Update all related case.
}
So my Javascript function is not complicated and lean.
You will not be able to Resolve incident when it has open activities (un-completed). And you have your Custom Dialog to resolve the case.
Good, you you have to get all the open service activities & update them as completed one by one before resolving case.
You can use your fetchxml query to get the data, then iterate through each record & make a service call to update.
You mentioned CRM 2016, is that update1 - then you can use web api.
Mohamed Amine Mahmoudi
83
Super User 2025 Season 1
Community Member
54
Victor Onyebuchi
6