viernes, 5 de agosto de 2011

Mismatching Sequence field values

Here comes the science poop:
Record with RecId 5637206524 in table 'Proyectos' has mismatching Sequence field values. Original value was 5637206523, new value is 5637206524.
No se puede editar un registro en Proyectos (ProjTable).
El número de registro no coincide con el número original. Si la tabla usa la caché completa, puede que la caché se esté vaciando. Reinicie su trabajo si es el caso.
It's not immediately clear what caused this for me. At first I'd put it down to the fact that I was stepping through code && iterating over a ProjTable with a cursor and my work colleague had updated the record I was attempting to change.

Now however I suspect that I was updating a 'stale' record as the error is only generated on the second pass through the loop.  I changed my code so that the first thing I did with my cursor is to obtain a copy of the cursor buffer with the find operation.
    for (cursorProjTable = ProjTable_ds.getFirst(true) ? ProjTable_ds.getFirst(true) :
        ProjTable_ds.cursor() ; cursorProjTable.RecId ; cursorProjTable = ProjTable_ds.getNext() )
    {
        projTableCpy.clear();
        projTableCpy = ProjTable::find(cursorProjTable.ProjId, true);

        this.op1(projTableCpy);
        this.op2(projTableCpy);
        this.op3(projTableCpy);

        // Update the record
        ttsbegin;
        projTableCpy.EVE_ProjWfStatus   = EVE_ProjWfStatus::Canceled;
        projTableCpy.Status             = ProjStatus::Completed;
        projTableCpy.update();

        // Use ProjStatusUpd the helper class to update the status of the project
//        projTableCpy.clear();
//        projTableCpy = ProjTable::find(cursorProjTable.ProjId, true);
//        projTableCpy.EVE_ProjWfStatus   = EVE_ProjWfStatus::Canceled;
//        projStatusUpd = ProjStatusUpd::construct(projTableCpy,ProjStatus::Completed);   //, true True for subprojects
//        projStatusUpd.run();
        ttscommit;
    }
As you can see from my pseudo-code above, I originally used the ProjStatusUpd class to peform my update but... I have the suspicion that something going on in there was causing our error.

The only useful link I could find on the web was to try selecting the record at the latest possible moment.  I removed the error, but without discovering exactly what was the root cause.

Edit : Daniel Kuettel has found a possible cause and provided a fix for a AX2009 SP1 instance.

1 comentario:

  1. The problem may be that it is trying to insert a record which already exists into ProdTableProj. It does this because of a bug in the sys layer in ProdTableForm.setDatasources(), where prodTableProjOver is wrongly set with prodTableProjError. Change prodTableProjOver = datasources3; to prodTableProjOver = datasources4; and the problem will be solved, if the situation applies to this scenario found in version 5.0.1500.3761.

    ResponderEliminar