Thursday, March 15, 2012

AX 2009 - creating a job to update a database field

I created the job using a basic SQL query to pull a record and then a method attached to that table that just added a defined variable amount to a date.



But that only did one record…   apparently I forgot the loop.  That was easy, just add while to the beginning of the select statement.


//ATLAS, Joseph Anderson - 03/14/2012 - J0001
static void ATL_jbAdjustRouteOprToDate(Args _args)
{
    ProdRoute pr;
    int idx = 0;
    ;

    ttsBegin;

        while select forUpdate pr
            where pr.OprFinished==0
        {
            pr.ATL_AdjustOprToDate = pr.AdjustToDate();
            pr.doUpdate();
            idx++;
        }

    ttsCommit;

//    update_recordset pr
//    setting
//        ATL_AdjustOprToDate = pr.AdjustToDate()
//    where OprFinished == 0;

    info(strFmt("Number of records updated is %1.", idx));
}

No comments: