Thursday, January 21, 2016

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

Search hierarchy for a match (TableALLGroup) X++

  Table1 ppt;  select firstonly ppt  order ItemCode, ItemRelation, AccountCode, AccountRelation where      (ppt.ItemCode == TableGroupAll::T...