Monday, January 16, 2017

Reversing Number sequence Ax 2012

public void revSequenceByOne(ItemGroupId _groupId)

{
          NumberSequenceTable     numberSeqTableRev,numberSeqLastRec;
          InventItemGroup         invItemGroup;
          str                     autonumber;
    
          ttsBegin;
          invItemGroup = InventItemGroup::find(_groupId);
    
          if (invItemGroup && invItemGroup.NumberSequenceCode)
          {
              autonumber = invItemGroup.NumberSequenceCode;
              numberSeqTableRev      = NumberSequenceTable::findByNaturalKey(autonumber);
    
              select forUpdate firstOnly numberSeqLastRec
                  where numberSeqLastRec.RecId == numberSeqTableRev.RecId;
              if (numberSeqLastRec.RecId && numberSeqLastRec.NextRec != 1)
              {
                 numberSeqLastRec.NextRec -= 1;
                 numberSeqLastRec.update();
              }
          }
          ttsCommit;
}

No comments:

Post a Comment