Running Batch Job from X++ example code

static void TID_ExecuteBatchJobDistribution(Args _args)
{
    BatchHeader header;
    SysRecurrenceData sysRecurrenceData;
    Batch batch;
    BatchJob batchJob;
    RetailConnScheduleRunner _RetailConnScheduleRunner; // Class extends RunBaseBatch
    BatchInfo processBatchInfo;
    BatchRetries noOfRetriesOnFailure = 4;
    ;

    // Setup the RunBaseBatch Job
    header = BatchHeader::construct();
    _RetailConnScheduleRunner = new RetailConnScheduleRunner();
    processBatchInfo = _RetailConnScheduleRunner.batchInfo();
    processBatchInfo.parmRetriesOnFailure(noOfRetriesOnFailure);
    processBatchInfo.parmCaption(_RetailConnSchedule.Name); // Description Batch Job
    processBatchInfo.parmGroupId('RTL'); // Batch Gorup
    processBatchInfo.parmBatchExecute(NoYes::Yes);
    header.addTask(_RetailConnScheduleRunner);

    // Set the recurrence data
    sysRecurrenceData = SysRecurrence::defaultRecurrence();
    SysRecurrence::setRecurrenceStartDateTime(sysRecurrenceData, DateTimeUtil::addSeconds(DateTimeUtil::utcNow(), 20)); // Set range of recurrence
    SysRecurrence::setRecurrenceNoEnd(sysRecurrenceData);
    SysRecurrence::setRecurrenceUnit(sysRecurrenceData, SysRecurrenceUnit::Minute); // Set reccurence pattern
    header.parmRecurrenceData(sysRecurrenceData);
    // Set the batch alert configurations
    header.parmAlerts(NoYes::No, NoYes::Yes, NoYes::No, NoYes::Yes, NoYes::Yes);
    header.save();

    // Update the frequency to run the job to every two minutes
    ttsbegin;
    select forupdate batchJob
    join batch
    where batchJob.RecId == batch.BatchJobId
    && batch.ClassNumber == classnum(RetailConnScheduleRunner);

    sysRecurrenceData = batchJob.RecurrenceData;
    sysRecurrenceData = conpoke(sysRecurrenceData, 8, [10]);
    batchJob.RecurrenceData = sysRecurrenceData;
    batchJob.update();
    ttscommit;
}
Advertisements

New contributors for hellodax !!

Hi there,
i’m Sti Fanddy Cavendish and working as AX Technical Consultant/Devoper. As far as i can remember, i started this blog just to write down my code so i dont have to spend more times to googling code that i had written. Now as Dynamics AX keep progressing, and the market expand more broader. The demand for x++ code and technical matters related to dynamics AX is much higher than few back years earlier. So i invited some of the best active AX Technical Consultant / Developer on Indonesia to joined this blog as new contributors. Hope they can share they experience regarding AX Technical.

Below are the new contributors for this blogs  :

Capture

Bagus Pramana (Author id : xylonitefuma) is an Senior AX Technical Consultant, his expertise on AX Retail, Architecture and AX POS customization is considered one of the best on the region.

Harrison Sibuea (Author id: atus) is an Senior AX Technical Consultant, his expertise on AX Customization on AX 2009, AX 2012. And and expert on AX Maintenance Support.

and last, the new Rookie , Randa Oktendy (Author id: axrokt) is an AX Developer , his expertise on AX and Report (SSRS) customization.

You can view all their linkedin profile on the Contributors section in this blog.  (https://hellodax.com/about/)

Thank you and happy daxing !!

 

 

How to access AX 7 from other machine (preview VM Version : AX7 Update 1)

version : AX7 Update 1.
When we need multiple users to test the new AX7 , it’s imposible to ask everyone to run VM on their local because not everyone have the specs to run the VM. So what i do is to make AX7 available on local network so our team can test its new features.

Step by step how to do it :
1. Setup network Bridged Adapter on VM settings

Capture

2. setup your network ip on inside your VM,  (cmd : ipconfig /all on host machine to view ip config)
Capture

3. Edit your local host file on C:\Windows\System32\drivers\etc . add AX 7 VM IP and usnconeboxax1aos.cloud.onebox.dynamics.com

Capture

4. Copy and install SSL certificate from VM to avoid HTTPS error when open the link. How to copy certificate : open IIS -> Website (AOSServiceDSC) -> Site Binding (on right pane) -> Edit Site Binding -> View SSL Certificate -> Details -> Copy to file .

Capture

5. install SSL certificate from VM to avoid HTTPS error when open the link. How to install certificate on the chrome.  url help link:

https://support.globalsign.com/customer/portal/articles/1211541-install-client-digital-certificate—windows-using-chrome

 

6. Now open your browser, and open the ax 7 at url at https://usnconeboxax1aos.cloud.onebox.dynamics.com , login using your credential, and voila !! done..

Capture

marking inventTrans example code

public static void FNDMarkInventTrans(InventTransId _inventTransId,InventTransId _refInventTransId,InventQty _qtyTomark)
{
    InventTrans issueInventTrans;
    TmpInventTransMark tmpInventTransMask;
    Map mapMarkNow;
    container con;
    real qty;
    Map mapTmp;
    MapEnumerator mapEnumerator;

    InventTransOriginId issueInventTransOriginId =
        InventTransOrigin::findByInventTransId(_inventTransId).RecId;

    InventTransOriginId receiptInventTransOriginId =
        InventTransOrigin::findByInventTransId(_refInventTransId).RecId;

    InventQty qtyToMark = _qtyTomark;

    ttsBegin;

    issueInventTrans = InventTrans::findByInventTransOrigin(
        issueInventTransOriginId);

    [con, qty] = TmpInventTransMark::packTmpMark(
        InventTransOrigin::find(issueInventTransOriginId),
        issueInventTrans.inventDim(),
        issueInventTrans.Qty);

    mapTmp = Map::create(con);
    mapEnumerator = mapTmp.getEnumerator();
    while (mapEnumerator.moveNext())
    {
        tmpInventTransMask = mapEnumerator.currentValue();

        if (tmpInventTransMask.InventTransOrigin == receiptInventTransOriginId)
        {
            tmpInventTransMask.QtyMarkNow = qtyToMark;
            tmpInventTransMask.QtyRemain -= tmpInventTransMask.QtyMarkNow;
            mapMarkNow = new Map(Types::Int64, Types::Record);
            mapMarkNow.insert(tmpInventTransMask.RecId, tmpInventTransMask);

            TmpInventTransMark::updateTmpMark(
                issueInventTransOriginId,
                issueInventTrans.inventDim(),
                -qtyToMark,
                mapMarkNow.pack());
        }
    }

    ttsCommit;
}

reference code :
https://community.dynamics.com/ax/b/dynamicsaxnotesonthecuffs/archive/2013/01/08/marking-from-code-part-2