Developer Q&A

Ask a Question
Back to All

ApStatusChangeCommand - Executes once, then WrongVersionException next time

Trying to execute an ApStatusChangeCommand to update a WorkOrderCost ApStatusId.

I have followed the pattern outlined in this question.

The first time it executes with no error. On all future invocations, the command returns "Corrigo.Core.WrongVersionException - Data was already modified by another user".

When I query the data again (even after the first time), the ApStatusId field is never actually updated.

I have tried adding ConcurrencyId, FinancialConcurrencyId, and CurrentStatusId with no effect. I have also tried setting ImposeConcurrencyId to false in net options, also to no effect. How can I successfully update ApStatusId?

Example code (C#):
var command = new ApStatusChangeCommand
{
WorkOrderId = workOrder.Id,
VendorInvoiceStatusId = (int)ApState.Disputed,
// Per reference material only the above two should be required. It doesn't multiple times with the below uncommented either
//Comment = comment,
//ActionDate = DateTime.Today,
//KeepCommentIntact = true,
//ConcurrencyId = workOrder.ConcurrencyId, // Must be included in Update requests (https://developer.corrigo.com/docs/create-entity)
//FinancialConcurrencyId = workOrder.WorkOrderCost.ConcurrencyId,
// CurrentStatusId = workOrder.WorkOrderCost.ApStatusId,

  };

  var response = await service.ExecuteAsync(new ExecuteRequest(CorrigoNetOptionsFactory.CreateDefault(), command));

  if (!(response.ExecuteResult.ErrorInfo is null))
  {
    var errorInfo = response.ExecuteResult.ErrorInfo;
    _log.LogError("Error updating work order: {type} - {description}", errorInfo.Type, errorInfo.Description);
    return false;
  }