locked
how to update invoice status and statecode RRS feed

  • Question

  • i am using this code but this is not working

      invoice crm_inv = new invoice();

                           crm_inv.invoiceid=new Key();

                           crm_inv.invoiceid.Value = invoiceid;

     

                           Status stus = new Status();

                           stus.Value = 100001;

                           crm_inv.statuscode = stus;

                           InvoiceStateInfo ins = new InvoiceStateInfo();

                           ins.Value = InvoiceState.Paid;

                           crm_inv.statecode=ins;

                           service.Update(crm_inv);

    exception occure server unable to process the request


    Faisal Imran
    Wednesday, June 8, 2011 4:34 PM

Answers

  • You cannot update the state of an entity using an update request, you must use the SetStateRequest:

    CrmService Crm4_service = connect();
    SetStateInvoiceRequest state = new SetStateInvoiceRequest();
    
    state.InvoiceState = InvoiceState.Paid;
    state.InvoiceStatus = 100001;
    state.EntityId = InvioceId;
    SetStateInvoiceResponse stateSet = (SetStateInvoiceResponse)Crm4_service.Execute(state);
    


    Gonzalo | gonzaloruizcrm.blogspot.com

    Wednesday, June 8, 2011 5:02 PM
    Moderator

All replies

  • You cannot update the state of an entity using an update request, you must use the SetStateRequest:

    CrmService Crm4_service = connect();
    SetStateInvoiceRequest state = new SetStateInvoiceRequest();
    
    state.InvoiceState = InvoiceState.Paid;
    state.InvoiceStatus = 100001;
    state.EntityId = InvioceId;
    SetStateInvoiceResponse stateSet = (SetStateInvoiceResponse)Crm4_service.Execute(state);
    


    Gonzalo | gonzaloruizcrm.blogspot.com

    Wednesday, June 8, 2011 5:02 PM
    Moderator
  • Hello Faisal,

    First thing - to SetState you should use SetState message instead of Update - http://technet.microsoft.com/en-us/library/bb959539.aspx

    Second - when you trying to execute some command you should use following approach to get detailed exception in the case server call will throw an error:

     

    try
    {
    //operations with crm service
    }
    catch(SoapException e)
    {
    throw new Exception(e.Detail.InnerText);
    }
    

     


    Microsoft CRM Freelancer

    My blog (english)
    Мой блог (русскоязычный)
    Wednesday, June 8, 2011 5:07 PM
    Moderator
  • thx Gonzalo problem solved
    Faisal Imran
    Wednesday, June 8, 2011 6:56 PM