Delete Global Number Sequence in x++ Dynamics 365 Finance and Operations

 Hi there, Recently I knew up with a problem in which one of my friends generated the wrong number sequence for this customization and now he had to remove it. I checked the scenario functionally if there is an option available for deleting the newly created number sequence as a whole because it was Globally generated and was not legal entity-specific. But alas I didn't get any way out except we generated a new number sequence.

But we can solve this problem easily using technical skills. You need to create a job that deletes the number sequence with all its reference from other tables as well. Below is the code for it. 

public class AA_RemoveNumSeqJob
{
/// <summary>
/// Runs the class with the specified arguments.
/// </summary>
/// <param name = "_args">The specified arguments.</param>

public static void main(Args _args)
{

  AA_RemoveNumSeqJob::DeleteNumSeqWithEDT(extendedTypeNum(AALoadId));
  info("Number sequence deleted");
}



public static void DeleteNumSeqWithEDT(ExtendedTypeId _dataTypeId )

{
  _dataTypeId = extendedTypeNum(AALoadId); // EDT USED 

  NumberSequenceDatatype numSeqDT; 

  NumberSequenceReference numSeqRef; 


  select forUpdate numSeqDT where
   numSeqDT.DatatypeId == _dataTypeId; // EDT Id


  delete_from numSeqRef where
   numSeqRef.NumberSequenceDatatype == numSeqDT.RecId;


  ttsBegin;

  numSeqDT.delete();
  
  ttsCommit;


  info( strFmt("Relation with EDT: %1 is removed.", numSeqDT.DatatypeId) );



 }
 

}

Happy Learning

Comments