locked
Error in plugin in CRM 2013 RRS feed

  • Question

  • I'm getting the following error in a plugin in CRM 2013: Incorrect attribute value type System.Int32

    The error is occuring in the following piece of code:

    private void UpdateEnquiry(ITracingService tracingService, IOrganizationService service, DateTime date, Guid EnquiryId)
            {
                // Create an update request. 
                try
                {
                    Entity entity = new Entity("new_enquiry");
                    entity.Id = EnquiryId;
                    tracingService.Trace("date: " + date);
                    if (date > DateTime.MinValue)
                    {
                        entity.Attributes["new_lastcustomersupplieddate"] = ConvertToLocalTime(service, date);
                        tracingService.Trace("entity.Attributes[new_lastcustomersupplieddate]: " + entity.Attributes["new_lastcustomersupplieddate"].ToString());
                        entity.Attributes["new_status"] = EnquiryStatus.Interim;
                        tracingService.Trace("entity.Attributes[new_status]: " + entity.Attributes["new_status"].ToString());
                    }
                    else
                    {
                        entity.Attributes["new_lastcustomersupplieddate"] = null;
                        tracingService.Trace("entity.Attributes[new_lastcustomersupplieddate]: " + entity.Attributes["new_lastcustomersupplieddate"].ToString());
                        entity.Attributes["new_status"] = EnquiryStatus.Pending;
                        tracingService.Trace("entity.Attributes[new_status]: " + entity.Attributes["new_status"].ToString());
                    }
                    UpdateRequest updateRequest = new UpdateRequest();
                    tracingService.Trace("Updating entity");
                    updateRequest.Target = entity;
                    UpdateResponse updateResponse = (UpdateResponse)service.Execute(updateRequest);
                    tracingService.Trace("updateResponse: " + updateResponse);
                    throw new InvalidPluginExecutionException();
                }
                catch (Exception ex)
                {
                    throw new InvalidPluginExecutionException("Error in UpdateEnquiry " +ex.ToString());
                }
                finally
                {
                }
    
            }
    The tracingService lines are my attempt to debug the plugin. They all appear in the log file, except the final one after the (UpdateResponse)service.Execute(updateRequest); line.

    Here's the full error from the log file, with the results of the tracing service lines:

    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Error in Execute Microsoft.Xrm.Sdk.InvalidPluginExecutionException: Error in UpdateEnquiry System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: Incorrect attribute value type System.Int32 (Fault Detail is equal to Microsoft.Xrm.Sdk.OrganizationServiceFault).
       at VS.CA.CRM.CustomerContactDate.SetLastSuppliedDate.UpdateEnquiry(ITracingService tracingService, IOrganizationService service, DateTime date, Guid EnquiryId)
       at VS.CA.CRM.CustomerContactDate.SetLastSuppliedDate.Execute(IServiceProvider serviceProvider)Detail:
    <OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
      <ErrorCode>-2147220891</ErrorCode>
      <ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
        <KeyValuePairOfstringanyType>
          <d2p1:key>OperationStatus</d2p1:key>
          <d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">0</d2p1:value>
        </KeyValuePairOfstringanyType>
        <KeyValuePairOfstringanyType>
          <d2p1:key>SubErrorCode</d2p1:key>
          <d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">-2146233088</d2p1:value>
        </KeyValuePairOfstringanyType>
      </ErrorDetails>
      <Message>Error in Execute Microsoft.Xrm.Sdk.InvalidPluginExecutionException: Error in UpdateEnquiry System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: Incorrect attribute value type System.Int32 (Fault Detail is equal to Microsoft.Xrm.Sdk.OrganizationServiceFault).
       at VS.CA.CRM.CustomerContactDate.SetLastSuppliedDate.UpdateEnquiry(ITracingService tracingService, IOrganizationService service, DateTime date, Guid EnquiryId)
       at VS.CA.CRM.CustomerContactDate.SetLastSuppliedDate.Execute(IServiceProvider serviceProvider)</Message>
      <Timestamp>2014-02-28T10:54:54.7594262Z</Timestamp>
      <InnerFault i:nil="true" />
      <TraceText>

    [VS.CA.CRM.CustomerContactDate: VS.CA.CRM.CustomerContactDate.SetLastSuppliedDate]
    [5912b703-3f28-e211-8c0a-3c4a92dbd8ab: VS.CA.CRM.CustomerContactDate.SetLastSuppliedDate: Update of new_customercontactdates]


    date: 2/27/2014 12:00:00 AM
    entity.Attributes[new_lastcustomersupplieddate]: 2/27/2014 1:00:00 AM
    entity.Attributes[new_status]: 2
    Updating entity


    </TraceText>
    </OrganizationServiceFault>

     

    Friday, February 28, 2014 11:16 AM

Answers

  • Hi,
    maybe the field "new_status" is an optionset? In this case you need to do the following:

    entity.Attributes["new_status"] = new OptionSetValue(2);

    I don't know the structure of your EnquiryStatus object, but the optionsetvalue parameter is an integer, probably also this will work:

      entity.Attributes["new_status"] = new OptionSetValue(EnquiryStatus.Interim);

    if your field "new_status" is not an optionset, please tell us the field type and explain the structure of the EnquiryStatus object 


    My blog: www.crmanswers.net - Rockstar 365 Profile

    • Marked as answer by crmNewbie1978 Friday, February 28, 2014 12:03 PM
    Friday, February 28, 2014 11:27 AM

All replies

  • Hi,
    maybe the field "new_status" is an optionset? In this case you need to do the following:

    entity.Attributes["new_status"] = new OptionSetValue(2);

    I don't know the structure of your EnquiryStatus object, but the optionsetvalue parameter is an integer, probably also this will work:

      entity.Attributes["new_status"] = new OptionSetValue(EnquiryStatus.Interim);

    if your field "new_status" is not an optionset, please tell us the field type and explain the structure of the EnquiryStatus object 


    My blog: www.crmanswers.net - Rockstar 365 Profile

    • Marked as answer by crmNewbie1978 Friday, February 28, 2014 12:03 PM
    Friday, February 28, 2014 11:27 AM
  • Thanks for your response. The "new_status" field is an optionset, so I updated the code like so:

           entity.Attributes["new_status"] = new OptionSetValue(EnquiryStatus.Pending);

    but I am still getting the same error:

    Unhandled Exception: System.ServiceModel.FaultException`1[[Microsoft.Xrm.Sdk.OrganizationServiceFault, Microsoft.Xrm.Sdk, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]]: Error in Execute Microsoft.Xrm.Sdk.InvalidPluginExecutionException: Error in UpdateEnquiry System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: Incorrect attribute value type System.Int32 (Fault Detail is equal to Microsoft.Xrm.Sdk.OrganizationServiceFault).
       at VS.CA.CRM.CustomerContactDate.SetLastSuppliedDate.UpdateEnquiry(ITracingService tracingService, IOrganizationService service, DateTime date, Guid EnquiryId)
       at VS.CA.CRM.CustomerContactDate.SetLastSuppliedDate.Execute(IServiceProvider serviceProvider)Detail: 
    <OrganizationServiceFault xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.microsoft.com/xrm/2011/Contracts">
      <ErrorCode>-2147220891</ErrorCode>
      <ErrorDetails xmlns:d2p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
        <KeyValuePairOfstringanyType>
          <d2p1:key>OperationStatus</d2p1:key>
          <d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">0</d2p1:value>
        </KeyValuePairOfstringanyType>
        <KeyValuePairOfstringanyType>
          <d2p1:key>SubErrorCode</d2p1:key>
          <d2p1:value xmlns:d4p1="http://www.w3.org/2001/XMLSchema" i:type="d4p1:string">-2146233088</d2p1:value>
        </KeyValuePairOfstringanyType>
      </ErrorDetails>
      <Message>Error in Execute Microsoft.Xrm.Sdk.InvalidPluginExecutionException: Error in UpdateEnquiry System.ServiceModel.FaultException`1[Microsoft.Xrm.Sdk.OrganizationServiceFault]: Incorrect attribute value type System.Int32 (Fault Detail is equal to Microsoft.Xrm.Sdk.OrganizationServiceFault).
       at VS.CA.CRM.CustomerContactDate.SetLastSuppliedDate.UpdateEnquiry(ITracingService tracingService, IOrganizationService service, DateTime date, Guid EnquiryId)
       at VS.CA.CRM.CustomerContactDate.SetLastSuppliedDate.Execute(IServiceProvider serviceProvider)</Message>
      <Timestamp>2014-02-28T11:38:39.2385786Z</Timestamp>
      <InnerFault i:nil="true" />
      <TraceText>
    
    [VS.CA.CRM.CustomerContactDate: VS.CA.CRM.CustomerContactDate.SetLastSuppliedDate]
    [5912b703-3f28-e211-8c0a-3c4a92dbd8ab: VS.CA.CRM.CustomerContactDate.SetLastSuppliedDate: Update of new_customercontactdates]
    
    date: 2/21/2014 12:00:00 AM
    entity.Attributes[new_lastcustomersupplieddate]: 2/21/2014 1:00:00 AM
    entity.Attributes[new_status]: 2
    Updating entity
    
    
    </TraceText>
    </OrganizationServiceFault>
    
    

    Friday, February 28, 2014 11:39 AM
  • Can you go to the definition of the EnquiryStatus enum and post here the code?
    If you can also check inside CRM the new_status optionset possible values (maybe they start with a prefix as 1000000,1000001,... instead of 1,2,3)


    My blog: www.crmanswers.net - Rockstar 365 Profile

    Friday, February 28, 2014 11:48 AM
  • Thank you for your reply. I had actually missed one instance of "new_status". When I updated that by adding new OptionSetValue it worked!
    Friday, February 28, 2014 12:03 PM