Create and Post Trade agreement using X++ , AX 2012

Hi , below job will create Trade agreement in AX 2012.

static void idbExecutePricPriceDiscJourSvcJob(Args _args)
{
    // PricePrice Vars
    PricePriceDiscJournalService            PriceDiscSvc;
    PricePriceDiscJournal                   PriceDiscJour;
    PricePriceDiscJournal_PriceDiscAdmTrans PriceDiscJourAdmTrans;
    PricePriceDiscJournal_InventDim         PriceDiscJourDim;
   
    // keys return from create process
    AifEntityKeyList                        keys;
 
    PriceDiscSvc = PricePriceDiscJournalService::construct();
    PriceDiscJour = new PricePriceDiscJournal();
    PriceDiscJourAdmTrans = PriceDiscJour.createPriceDiscAdmTrans().addNew();
    PriceDiscJourDim = PriceDiscJourAdmTrans.createInventDim().addNew();

    // Set PriceDiscJourDim
    PriceDiscJourDim.parminventDimId(“your dim id”);

    // Set PriceDiscJourAdmTrans
   // PriceDiscJourAdmTrans.parmInventDim().add(PriceDiscJourDim);
    PriceDiscJourAdmTrans.parmItemRelation(InventTable::findByProduct( your product).ItemId);
    PriceDiscJourAdmTrans.parmItemCode(TableGroupAll::Table);
    PriceDiscJourAdmTrans.parmAmount(100.00);
    PriceDiscJourAdmTrans.parmFromDate(today());
    PriceDiscJourAdmTrans.parmAccountCode(TableGroupAll::All);
    PriceDiscJourAdmTrans.parmrelation(PriceType::PriceSales);
    PriceDiscJourAdmTrans.parmCurrency(“USD”);
   

    // Post PriceDiscJour
    keys = PriceDiscSvc.create(PriceDiscJour);
        }
    }
}

How ever , this will only create trade agreement .
If you want to post automatically, then you neeed to modify the “priceDiscAdmCheckPost” method of class

public void priceDiscAdmCheckPost()
{
    PriceDiscAdmCheckPost   priceDiscAdmCheckPost = new PriceDiscAdmCheckPost(false);//To make sure posting is happen

    if (initNoErrorsInInfolog == infolog.num(Exception::Error))
    {
        priceDiscAdmCheckPost.initJournalNum(priceDiscAdmTable.JournalNum);
        priceDiscAdmCheckPost.run();
    }
}

4 thoughts on “Create and Post Trade agreement using X++ , AX 2012”

  1. Thanks for the post. But if you don't clear the infolog, it doesn't post.

    infolog.clear(); jourPost.initJournalNum(priceDiscAdmTrans.JournalNum);
    jourPost.run();

  2. I missed this part of the code to be able to post it from the job.

        // Post PriceDiscJour
        keys = PriceDiscSvc.create(PriceDiscJour);
    journalNum = keys.getEntityKey(1).parmKeyDataMap().lookup(fieldnum(PriceDiscAdmTrans, JournalNum));

    info(strFmt("%1", journalNum));
        priceDiscAdmCheckPost = new PriceDiscAdmCheckPost(false);//To make sure posting is happen
        priceDiscAdmCheckPost.initJournalNum(journalNum);
        priceDiscAdmCheckPost.run();

Leave a Reply

Your email address will not be published. Required fields are marked *