Saturday 11 July 2020

Create delivery schedule for purchase line via x++ in ax 2012

I was supposed to create a delivery schedule for purchase lines via code and I created this job from the form, how the delivery schedule lines created in the backend.

The most important thing to handle is, the line number for the delivery lines. The logic needs to be created if you want to use custom line number else you can stick to the standard line numbering.

static void CreateDLVSchedule(Args _args)
{    
    List                                newScheduleLines = new List(Types::Container);
    PurchLine               		purchLine, purchLineNew;
    PurchDeliverySchedule   		purchDeliverySchedule;
    
    PurchTableForm_DeliverySchedule 	purchTableForm_DeliverySchedule;
    
    select purchLine
        where purchLine.PurchId == "PurchId"
        && purchLine.LineNumber == 10;
    
    purchTableForm_DeliverySchedule = PurchTableForm::construct(PurchTableFormId::DeliverySchedule, purchLine);    
    
    purchLineNew.setTmp();
    
    purchLineNew.data(purchLine.data());    
    
    purchTableForm_DeliverySchedule.purchLine_Init(purchLineNew);
    purchLineNew.LineNumber = purchLine.LineNumber + 1; // Add your logic to spcify line number
    purchTableForm_DeliverySchedule.purchLine_CreatePreSuper(purchLineNew);    
    newScheduleLines.addEnd([purchLineNew]);

    purchTableForm_DeliverySchedule.parmScheduleLines(newScheduleLines);
    purchTableForm_DeliverySchedule.parmMarkupConversionMode(DlvScheduleMarkupConversionMode::Copy);
    purchTableForm_DeliverySchedule.updateSchedule();
    
    info("Done");

}

2 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. Hi! I used this code and in the first run it works good. Now, I have to modify this first schedule version and when I execute de same code change the quantity of the original purchLine. I try several changes into your code but I could not get the key to modifiy the schedule.
    For example, In a situation I need to delete all schedules and create new ones.
    Did you have to do this any time? Could you please help me? Thanks

    ReplyDelete

Calculate ledger balance by dimension set in X++ in AX2012/Dynamics 365 FO

There are a variety of ways users can view balances in the general ledger. Some of the most common options are: 1. Trial balance 2. Financia...