SBX - Search With Button

SBX - Forum Post Title

Service Activity 'There should be only one owner party for an activity' after upgrade from 2015 to 2016 (on premise)

Microsoft Dynamics CRM Forum

Derekm asked a question on 11 Apr 2017 4:26 PM
My Badges

Question Status

Verified

Last week we upgraded from CRM 2015 to CRM 2016 and also Installed SP1.


Since then on some random Service Activities we get a business process error when trying to delete or reassigning them.  In the Error log it shows some generic info and mentions a plugin we use.  Here is the error I get when trying to delete a Service Activity from an affected Case.

Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: System.Web.HttpUnhandledException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #A03B2C8FDetail: 
<OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance" xmlns="schemas.microsoft.com/.../Contracts">
  <ErrorCode>-2147220970</ErrorCode>
  <ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic" />
  <Message>System.Web.HttpUnhandledException: Microsoft Dynamics CRM has experienced an error. Reference number for administrators or support: #A03B2C8F</Message>
  <Timestamp>2017-04-11T21:20:45.0755066Z</Timestamp>
  <InnerFault>
    <ErrorCode>-2147220891</ErrorCode>
    <ErrorDetails xmlns:d3p1="schemas.datacontract.org/.../System.Collections.Generic" />
    <Message>An error occured while processing this request.</Message>
    <Timestamp>2017-04-11T21:20:45.0755066Z</Timestamp>
    <InnerFault i:nil="true" />
    <TraceText>

[MSCRM_Hours_Account_Plugin: MSCRM_Hours_Account_Plugin.Plugin]
[78b3e2af-e559-e311-80bd-001e6764dea8: MSCRM_Hours_Account_Plugin.Plugin: Delete of serviceappointment]


</TraceText>
  </InnerFault>
  <TraceText i:nil="true" />
</OrganizationServiceFault>

However in the Event Viewer I can see the "There should be only one owner party for an activity" error below.

The Web Service plug-in failed in OrganizationId: e66d88ca-93c6-44fc-8f1a-00c9595a3afc; SdkMessageProcessingStepId: 78b3e2af-e559-e311-80bd-001e6764dea8; EntityName: serviceappointment; Stage: 20; MessageName: Delete; AssemblyName: MSCRM_Hours_Account_Plugin.Plugin, MSCRM_Hours_Account_Plugin, Version=1.0.0.0, Culture=neutral, PublicKeyToken=797d3454956c826c; ClassName: MSCRM_Hours_Account_Plugin.Plugin; Exception: Unhandled Exception: Microsoft.Xrm.Sdk.SaveChangesException: An error occured while processing this request.
   at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.SaveChanges(SaveChangesOptions options)
   at MSCRM_Hours_Account_Plugin.Plugin.Execute(IServiceProvider serviceProvider)
   at Microsoft.Crm.Extensibility.V5PluginProxyStep.ExecuteInternal(PipelineExecutionContext context)
   at Microsoft.Crm.Extensibility.VersionedPluginProxyStepBase.Execute(PipelineExecutionContext context)
Inner Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=8.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: There should be only one owner party for an activityDetail: 
<OrganizationServiceFault xmlns:i="www.w3.org/.../XMLSchema-instance" xmlns="schemas.microsoft.com/.../Contracts">
  <ErrorCode>-2147220989</ErrorCode>
  <ErrorDetails xmlns:d2p1="schemas.datacontract.org/.../System.Collections.Generic" />
  <Message>There should be only one owner party for an activity</Message>
  <Timestamp>2017-04-11T17:28:31.2752068Z</Timestamp>
  <InnerFault>
    <ErrorCode>-2147220989</ErrorCode>
    <ErrorDetails xmlns:d3p1="schemas.datacontract.org/.../System.Collections.Generic" />
    <Message>There should be only one owner party for an activity</Message>
    <Timestamp>2017-04-11T17:28:31.2752068Z</Timestamp>
    <InnerFault>
      <ErrorCode>-2147220989</ErrorCode>
      <ErrorDetails xmlns:d4p1="schemas.datacontract.org/.../System.Collections.Generic" />
      <Message>There should be only one owner party for an activity</Message>
      <Timestamp>2017-04-11T17:28:31.2752068Z</Timestamp>
      <InnerFault i:nil="true" />
      <TraceText i:nil="true" />
    </InnerFault>
    <TraceText i:nil="true" />
  </InnerFault>
  <TraceText i:nil="true" />
</OrganizationServiceFault>
   at Microsoft.Crm.Extensibility.OrganizationSdkServiceInternal.Execute(OrganizationRequest request, CorrelationToken correlationToken, CallerOriginToken callerOriginToken, WebServiceType serviceType, Boolean checkAdminMode, ExecutionContext executionContext)
   at Microsoft.Crm.Extensibility.InprocessServiceProxy.ExecuteCore(OrganizationRequest request)
   at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.Execute(OrganizationRequest request)
   at Microsoft.Xrm.Sdk.Client.OrganizationServiceContext.SaveChange(OrganizationRequest request, IList`1 results)

This seems to happen to any Service Activity assigned to specific cases.  It doesn't happen with every case, very few in fact, but once it happens with a case any activity created will get the error if you attempt to delete it or assign it.

In trying to resolve this problem I found on Google that this can be related to activities having no owner, or having multiple owners.  I tried to the 2 SQL scripts here to see if I could identify those records, but both queries return 0 results.

I don't know if this is related to our plugin, even though the business process error does mention it.  It doesn't happen with the majority of activities or cases in our system and we go through a few hundred new ones per day.  And this all worked perfectly before the update from 2016 to 2015.  We didn't touch the plugins before or after the change.


Any ideas what else we could try?  I can give more info if necessary.

Reply
Ramanathan Rajendran responded on 12 Apr 2017 7:33 PM
My Badges

From the errors I could see the issues is with plugin which you may need to fix.  

Disable the plugin step and test. If it works then the issue is with plugin.

To disable

Go to default solution => SdkMessageProcessingStep => Find the plugin and disable it.

Reply
Derekm responded on 13 Apr 2017 9:42 AM
My Badges

Thanks.  I'll look further into the plugin.  Unfortunately the original dev has left our company so Im a bit in the wind with this.

Was anything major changed with how plugins work from 2015 to 2016?  That might give me a starting point on where to look.

I notice it uses an XRM.cs that says it was auto generated.  Would I need to generate a new one for 2016?

Reply
Mohamed Mostafa responded on 13 Apr 2017 9:48 AM
My Badges
Suggested Answer

Hi Derek

There has been changes but not major from 2015 to 2016 SP1. However, you normally should always test your code as part of your upgrade planning and testing. If you have made any changes to the data model that may affect your plugins execution.

As for the XRM.cs, again that may need to be re-generated if you are going to upgrade your plugin code to work with the upgraded version.

Hope this helps! Please mark "verify answer" if you found this response helpful.

Reply
Derekm responded on 13 Apr 2017 9:56 AM
My Badges

Thanks.  Unfortunately this is such a rare occurrence it was not caught in testing.  It works as expected on 99% of records, which is why I thought it might not be an issue with the plugin and more related to the multiple activity owners error.

Is there a guide on how I can generate the XRM.CS?

Reply
Ramanathan Rajendran responded on 13 Apr 2017 1:36 PM
My Badges

At this point, I cannot confirm that it will fix the error if regenerated, but there is a chance!

You may need some dev help on this to sort out the error!

Also another quick thought, there can be a data migration issue. From the error , it states that the particular activity has two owners in partylist(ActivityParty).

Reply
Alex Shlega responded on 13 Apr 2017 2:01 PM
My Badges

Hi Derek,

 you wrote the same error is happening when you are trying to reassign, so you might also want to confirm if you can find anything about this plugin in the error log in those cases. Just to make sure it's, actually, the plugin that's responsible..

 Besides. maybe you could post the code here (not sure how much help we can provide, but who knows:) )

PS. Looking at those SQL queries you mentioned.. it seems that this error is not necessarily specific to your plugin - it's the data that may be corrupted and the plugin is simply doing something that's causing that underlying problem with data to show up

Reply
Derekm responded on 13 Apr 2017 3:49 PM
My Badges

I updated the plugin to the latest SDK and replaced all the references, generated a new XRM.cs file, and still no luck.

Here is the plugin source if anyone has any ideas.  The filen below is Plugin.cs, the only other file in the plugin is the XRM.cs.  Let me know if you have any ideas.  Otherwise I plan to make a MS support call after Easter to see if we can narrow down if the issue is data related or plugin related.

namespace COMPANY_Hours_Account_Plugin
{
    using System;
    using System.Collections.ObjectModel;
    using System.Globalization;
    using System.Linq;
    using System.ServiceModel;
    using Microsoft.Xrm.Sdk;
    using Xrm;
    using Microsoft.Crm.Sdk.Messages;
    using Microsoft.Xrm.Sdk.Query;

    /// <summary>
    /// Base class for all Plugins.
    /// </summary>    
    public class Plugin : IPlugin
    {
       
        public void Execute(IServiceProvider serviceProvider)
        {
            //THIS PLUGIN UPDATES THE BALANCE OF THE HOURS ACCOUNT AND THE RELATED CASE WHEN A SERVICE ACTIVITY IS MODIFIED OR DELETED
            if (serviceProvider == null)
            {
                throw new ArgumentNullException("serviceProvider");
            }

            // Construct the Local plug-in context.
            IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));
            Entity entity;
            if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity && ((Entity)context.InputParameters["Target"]).LogicalName == "serviceappointment")
            {
                try
                {
                   entity = (Entity)context.InputParameters["Target"];
                   IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);
                    using (var xrm = new XrmServiceContext(service))
                    {
                        ServiceAppointment curService = xrm.ServiceAppointmentSet.Where(a => a.Id == entity.Id).FirstOrDefault();
                        if (curService!=null && curService.new_HoursAccountId != null)
                        {
                            decimal curBalance = 0M;
                            Guid hoursAccountId = curService.new_HoursAccountId.Id;
                            new_hours_account curHoursAccount = xrm.new_hours_accountSet.Where(a => a.Id == hoursAccountId && (int)a.statecode == 0).FirstOrDefault();
                            if (curHoursAccount != null)
                            {
                                new_hours_account_statement lastStatement = (new_hours_account_statement)xrm.new_hours_account_statementSet.Where(a => a.new_HoursAccountId.Id == hoursAccountId && a.statecode.Value == 0).OrderByDescending(b => b.new_DateTo).FirstOrDefault();
                                if (lastStatement != null)
                                    curBalance = lastStatement.new_EndingHoursBalance != null ? (decimal)lastStatement.new_EndingHoursBalance : 0M;
                                var serviceAppointments = xrm.ServiceAppointmentSet.Where(a => a.new_HoursAccountId.Id == hoursAccountId && a.new_new_hours_account_statement_serviceappointment_HoursAccountStatement == null && (int)a.StateCode.Value != 2);
                                foreach (ServiceAppointment aService in serviceAppointments)
                                    curBalance -= aService.new_BilledDuration != null ? (decimal)aService.new_BilledDuration : 0M;
                                curHoursAccount.new_Current_Balance = curBalance;
                                xrm.UpdateObject(curHoursAccount);
                                xrm.SaveChanges();
                            }
                        }

                        //UPDATE THE TOTAL NUMBER OF MINUTES FOR THE CASE
                        int curActualDuration = 0;
                        decimal curCaseBilled = 0M;
                        decimal curCaseCOMPANY = 0M;
                        if (curService != null &&  curService.RegardingObjectId != null && curService.RegardingObjectId.LogicalName == "incident")
                        {
                            Incident curCase = xrm.IncidentSet.Where(a => a.Id == curService.RegardingObjectId.Id && (int)a.StateCode != 2).FirstOrDefault();
                            if (curCase != null)
                            {
                                int curCaseState = (int)curCase.StateCode.Value;
                                int curCaseStatus=curCase.StatusCode.Value;
                                IncidentResolution aResolution=null;
                                bool bNeedToReopen = false;
                                if (curCaseState ==1)
                                {
                                    //the case is canceled or resolved and need to be reactivated before updating it
                                    OpenIncident(curCase, service);
                                    Guid aCaseId = curCase.Id;
                                    if(curCase.Incident_IncidentResolutions!=null)
                                        aResolution = curCase.Incident_IncidentResolutions.LastOrDefault();
                                    xrm.Detach(curCase);
                                    curCase = xrm.IncidentSet.Where(a => a.Id == curService.RegardingObjectId.Id && (int)a.StateCode != 2).FirstOrDefault();
                                    //curCase = service.Retrieve(Incident.EntityLogicalName, aCaseId, new ColumnSet(allColumns: true)).ToEntity<Incident>();
                                    bNeedToReopen = true;
                                }
                                if (curCase != null)
                                {
                                    // get the services associated with the case
                                    var serviceAppointments2 = xrm.ServiceAppointmentSet.Where(a => a.RegardingObjectId != null && a.RegardingObjectId.Id == curCase.Id && (int)a.StateCode != 2);
                                    foreach (ServiceAppointment aService in serviceAppointments2)
                                    {
                                        curActualDuration += aService.ActualDurationMinutes != null ? (int)aService.ActualDurationMinutes : 0;
                                        curCaseBilled += aService.new_BilledDuration != null ? (decimal)aService.new_BilledDuration : 0M;
                                        curCaseCOMPANY += aService.new_COMPANYTime != null ? (decimal)aService.new_COMPANYTime : 0M;
                                    }
                                    curCase.ActualServiceUnits = curActualDuration;
                                    curCase.new_BilledTime = curCaseBilled;
                                    curCase.new_COMPANYTime = curCaseCOMPANY;
                                    xrm.UpdateObject(curCase);
                                    xrm.SaveChanges();
                                    if (bNeedToReopen)
                                    {
                                        CloseIncident(curCase, service, aResolution, curCaseStatus);
                                    }
                                }
                            }
                        }
                    }
                }
                catch (FaultException<OrganizationServiceFault> ex)
                {
                    throw new InvalidPluginExecutionException("An error occurred updating Hours Account Balance - ", ex.InnerException);
                }
            }
            else if(context.InputParameters.Contains("Target") && context.InputParameters["Target"] is EntityReference)
            {
                //THIS SECTION RUN WHEN THE SERVICE ACTIVITY IS BEING DELETED
                try
                {
                    var entityref = (EntityReference)context.InputParameters["Target"];
                    if (entityref != null && entityref.LogicalName!=null && entityref.LogicalName.ToLower() != "serviceappointment")
                        return;
                    IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
                    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);


                    using (var xrm = new XrmServiceContext(service))
                    {

                        ServiceAppointment curService = xrm.ServiceAppointmentSet.Where(a => a.Id == entityref.Id).FirstOrDefault();
                        //If service is posted to a statement abort the delete operation
                        if (curService != null)
                        {
                            if (curService.new_HoursAccountStatementId != null)
                            {
                                throw new Exception("This service was posted and cannot be deleted");
                            }

                            //if the case is resolved, the service cannot be deleted
                            if (curService.RegardingObjectId != null && curService.RegardingObjectId.LogicalName == "incident")
                            {
                                Incident curCase = xrm.IncidentSet.Where(a => a.Id == curService.RegardingObjectId.Id && (int)a.StateCode != 2).FirstOrDefault();
                                if (curCase != null)
                                {
                                    int curCaseState = (int)curCase.StateCode.Value;
                                    if (curCaseState == 1)
                                    {
                                        throw new Exception("This service cannot be deleted because it has a refrence to a resolved case. The case needs to be reactivated first.");
                                    }
                                    else
                                    {
                                        int curActualDuration = 0;
                                        decimal curCaseBilled = 0M;
                                        decimal curCaseCOMPANY = 0M;
                                        var serviceAppointments = xrm.ServiceAppointmentSet.Where(a => a.Id != curService.Id && a.RegardingObjectId != null && a.RegardingObjectId.Id == curCase.Id && (int)a.StateCode != 2);
                                        foreach (ServiceAppointment aService in serviceAppointments)
                                        {
                                            curActualDuration += aService.ActualDurationMinutes != null ? (int)aService.ActualDurationMinutes : 0;
                                            curCaseBilled += aService.new_BilledDuration != null ? (decimal)aService.new_BilledDuration : 0M;
                                            curCaseCOMPANY += aService.new_COMPANYTime != null ? (decimal)aService.new_COMPANYTime : 0M;
                                        }
                                        curCase.ActualServiceUnits = curActualDuration;
                                        curCase.new_BilledTime = curCaseBilled;
                                        curCase.new_COMPANYTime = curCaseCOMPANY;
                                        xrm.UpdateObject(curCase);
                                        xrm.SaveChanges();
                                    }
                                }
                            }
                            decimal curBalance = 0M;
                            if (curService.new_HoursAccountId != null)
                            {
                                Guid hoursAccountId = curService.new_HoursAccountId.Id;
                                new_hours_account curHoursAccount = xrm.new_hours_accountSet.Where(a => a.Id == hoursAccountId && (int)a.statecode == 0).FirstOrDefault();
                                if (curHoursAccount != null)
                                {
                                    new_hours_account_statement lastStatement = (new_hours_account_statement)xrm.new_hours_account_statementSet.Where(a => a.new_HoursAccountId.Id == hoursAccountId && a.statecode.Value == 0).OrderByDescending(b => b.new_DateTo).FirstOrDefault();
                                    if (lastStatement != null)
                                        curBalance = lastStatement.new_EndingHoursBalance != null ? (decimal)lastStatement.new_EndingHoursBalance : 0M;
                                    var serviceAppointments = xrm.ServiceAppointmentSet.Where(a => a.Id != curService.Id && a.new_HoursAccountId.Id == hoursAccountId && a.new_new_hours_account_statement_serviceappointment_HoursAccountStatement == null && (int)a.StateCode != 2);
                                    foreach (ServiceAppointment aService in serviceAppointments)
                                        curBalance -= aService.new_BilledDuration != null ? (decimal)aService.new_BilledDuration : 0M;
                                    curHoursAccount.new_Current_Balance = curBalance;
                                    xrm.UpdateObject(curHoursAccount);
                                    xrm.SaveChanges();
                                }
                            }
                        }
                    }
                }
                catch (FaultException<OrganizationServiceFault> ex)
                {
                    throw new InvalidPluginExecutionException("An error occurred: - ", ex);
                }
            }
        }

        public void OpenIncident(Incident entity, IOrganizationService aService)
        {
            SetStateRequest setStateReq = new SetStateRequest();
            //Pass GUID of the record to be activated or Deactivated

            setStateReq.EntityMoniker = new EntityReference(entity.LogicalName, entity.Id);
            setStateReq.State = new OptionSetValue(0);
            setStateReq.Status = new OptionSetValue(1);
            SetStateResponse setStateResponse = (SetStateResponse)aService.Execute(setStateReq);
        }

        public void CloseIncident(Incident entity, IOrganizationService aService,IncidentResolution aResolution, int aNewStatus)
        {
            CloseIncidentRequest closeRequest = new CloseIncidentRequest();
            if (aResolution == null)
            {
                aResolution = new IncidentResolution();
                aResolution.Subject = "Case Closed";
                aResolution.IncidentId = new EntityReference(Incident.EntityLogicalName,entity.Id);
            }
            closeRequest.IncidentResolution = aResolution;
            closeRequest.Status = new OptionSetValue(aNewStatus);
            CloseIncidentResponse closeResponse = (CloseIncidentResponse)aService.Execute(closeRequest);
        }

        public static void Test(XrmServiceContext xrm, string theServiceGuid)
        {
            if (xrm == null ||string.IsNullOrEmpty(theServiceGuid))
            {
                throw new ArgumentNullException("serviceProvider");
            }

            // Construct the Local plug-in context.
            try
            {
                Guid id = new Guid(theServiceGuid);
                var curService = (ServiceAppointment)xrm.ServiceAppointmentSet.Where(a=> a.Id==id).FirstOrDefault();

               decimal curBalance = 0M;
                new_hours_account_statement lastStatement = (new_hours_account_statement)xrm.new_hours_account_statementSet.Where(a => a.new_HoursAccountId.Id == curService.new_HoursAccountId.Id).OrderByDescending(b => b.new_DateTo).FirstOrDefault();
                if (lastStatement != null)
                    curBalance = lastStatement.new_EndingHoursBalance != null ? (decimal)lastStatement.new_EndingHoursBalance : 0M;
                var serviceAppointments = xrm.ServiceAppointmentSet.Where(a => a.new_HoursAccountId.Id == curService.new_HoursAccountId.Id && a.new_new_hours_account_statement_serviceappointment_HoursAccountStatement == null && (int) a.StateCode !=2);
                foreach (ServiceAppointment aService in serviceAppointments)
                    curBalance -= aService.new_BilledDuration != null ? (decimal)aService.new_BilledDuration : 0M;
                new_hours_account curHoursAccount = xrm.new_hours_accountSet.Where(a => a.Id == curService.new_HoursAccountId.Id).FirstOrDefault();
                curHoursAccount.new_Current_Balance = curBalance;
                xrm.UpdateObject(curHoursAccount);
                xrm.SaveChanges();

                //UPDATE THE TOTAL NUMBER OF MINUTES FOR THE CASE
                int curActualDuration = 0;
                decimal curCaseBilled = 0M;
                decimal curCaseCOMPANY = 0M;
                if (curService.RegardingObjectId.LogicalName == "incident")
                {
                    Incident curCase = xrm.IncidentSet.Where(a => a.Id == curService.RegardingObjectId.Id && (int)a.StateCode != 2).FirstOrDefault();
                    if (curCase != null)
                    {
                        // get the services associated with the case
                        serviceAppointments = xrm.ServiceAppointmentSet.Where(a => a.RegardingObjectId!=null &&  a.RegardingObjectId.Id == curCase.Id &&(int)a.StateCode != 2);
                        foreach (ServiceAppointment aService in serviceAppointments)
                        {
                            curActualDuration += aService.ActualDurationMinutes != null ? (int)aService.ActualDurationMinutes : 0;
                            curCaseBilled += aService.new_BilledDuration != null ? (decimal)aService.new_BilledDuration : 0M;
                            curCaseCOMPANY += aService.new_COMPANYTime != null ? (decimal)aService.new_COMPANYTime : 0M;
                        }
                        curCase.ActualServiceUnits = curActualDuration;
                        curCase.new_BilledTime = curCaseBilled;
                        curCase.new_COMPANYTime = curCaseCOMPANY;
                        xrm.UpdateObject(curCase);
                        xrm.SaveChanges();
                    }
                }


               }
            catch (FaultException<OrganizationServiceFault> ex)
            {
                throw new InvalidPluginExecutionException("An error occurred updating Hours Account Balance - ", ex);
            }
        }
        
    }
}


Appreciate the help!

Reply
Ramanathan Rajendran responded on 13 Apr 2017 3:57 PM
My Badges

For a record that errors out, can you retrieve the partylist associated to it and analyze the data. Also hope this issue occurs with the existing records and not with the new one's!

Reply
Derekm responded on 13 Apr 2017 4:00 PM
My Badges

It seems to be on an account by account basis.  So any account that is affected has every service activity and case also affected.

New accounts are not picking up this issue as far as I know, but we don't necessarily have a lot of new accounts daily so it could happen still.

Given that whats the best way to find the partylist?  Can accounts or other entities have more than 1 party?  I know activities have an activitypartybase table, but other entities don't seem to.

Reply
Alex Shlega responded on 13 Apr 2017 4:16 PM
My Badges
Verified Answer

Might not answer your question yet, but might get you closer..

- The error message is mentioning SaveChanges

- In the "delete" portion of the plugin there are two calls to the SaveChanges

The problem with those calls (I think) is that they are actually updating ALL the attributes on the account/case (even if, for the most part, they are just re-setting those attributes)

Where I'm going is: those calls are also updating the "owner" field (again, just resetting it)

According to Microsoft, such updates are now equivalent to AssignRequests. That could be the difference between your older CRM and current CRM

Why it might matter? If an account/case are "re-assigned", CRM might try to propagate those changes to the service activity being deleted through the relationship. Not sure why it would fail.. but, maybe, it only fails where those activities are currently assigned to other owners?

What I would try is the following update syntax instead:

new_hours_account updatedAccount = new new_hours_account();

updatedAccount.Id = curHoursAccount.Id;

updatedAccount.new_Current_Balance = curBalance;

service.Update(updatedAccount);

That would be instead of

xrm.UpdateObject(curHoursAccount);

xrm.SaveChanges();

Same thing with the incident

(And you can optimize it more after that, but that's just a quick "test")

Reply
Derekm responded on 13 Apr 2017 4:18 PM
My Badges

Thanks, Ill have to give that a try next week.  Will report back!

Reply
Alex Shlega responded on 13 Apr 2017 4:23 PM
My Badges

Just updated that post slightly.. Anyway, good luck

Reply
Ramanathan Rajendran responded on 13 Apr 2017 4:41 PM
My Badges

Update the org name and guid of the service activity in the below odata url and run it in chrome. If it returns more than one record for the activity( which has error) then its a data issue. Let us know on the results.

https://yourorg.crm.dynamics.com/XRMServices/2011/OrganizationData.svc/ActivityPartySet?$select=ActivityPartyId,ParticipationTypeMask,PartyId,&$filter=ParticipationTypeMask/Value eq 9 and ActivityId/Id eq (Guid'748fea2e-c39c-4d74-abce-9f12f05c5e97')

Reply
Alex Shlega responded on 13 Apr 2017 6:22 PM
My Badges

It's, actually, easy to reproduce with an on-delete workflow that re-assigns SA case to another user:

You need to fix that SaveChanges part of the plugin..

Reply
Ramanathan Rajendran responded on 13 Apr 2017 6:54 PM
My Badges

Nice find!

Reply
Alex Shlega responded on 13 Apr 2017 4:16 PM
My Badges
Verified Answer

Might not answer your question yet, but might get you closer..

- The error message is mentioning SaveChanges

- In the "delete" portion of the plugin there are two calls to the SaveChanges

The problem with those calls (I think) is that they are actually updating ALL the attributes on the account/case (even if, for the most part, they are just re-setting those attributes)

Where I'm going is: those calls are also updating the "owner" field (again, just resetting it)

According to Microsoft, such updates are now equivalent to AssignRequests. That could be the difference between your older CRM and current CRM

Why it might matter? If an account/case are "re-assigned", CRM might try to propagate those changes to the service activity being deleted through the relationship. Not sure why it would fail.. but, maybe, it only fails where those activities are currently assigned to other owners?

What I would try is the following update syntax instead:

new_hours_account updatedAccount = new new_hours_account();

updatedAccount.Id = curHoursAccount.Id;

updatedAccount.new_Current_Balance = curBalance;

service.Update(updatedAccount);

That would be instead of

xrm.UpdateObject(curHoursAccount);

xrm.SaveChanges();

Same thing with the incident

(And you can optimize it more after that, but that's just a quick "test")

Reply
Mohamed Mostafa responded on 13 Apr 2017 9:48 AM
My Badges
Suggested Answer

Hi Derek

There has been changes but not major from 2015 to 2016 SP1. However, you normally should always test your code as part of your upgrade planning and testing. If you have made any changes to the data model that may affect your plugins execution.

As for the XRM.cs, again that may need to be re-generated if you are going to upgrade your plugin code to work with the upgraded version.

Hope this helps! Please mark "verify answer" if you found this response helpful.

Reply

SBX - Two Col Forum

SBX - Migrated JS