Wednesday 7 November 2012

Create Pull jobs for newly created Tables in AX retail 2012


How To Create Pull  jobs for newly created Tables in AX retail 2012.

For creating Pull  jobs for newely created tables, we need to follow the following steps :

1 . Create a new table  as below :
 2.Add below fields in table other than your normal fields :

RetailTerminalId
RetailStoreId
RetailStatementId
RetailStaffId
ReplicationCounter

3.Add below two methods in your table :



  public RetailReplicationCounter maxReplicationCounterFromOrigin(RetailConnDistributionLocationId _locationId)
{
    RetailPosBatchTable  posBatchTable;
    RetailTerminalTable terminalTable;

    if (_locationId)
    {
        if (RetailStoreTable::find(_locationId))
        {
            select maxof(ReplicationCounter) from posBatchTable
            where posBatchTable.StoreId == _locationId;
        }
        else
        {
            terminalTable = RetailTerminalTable::find(_locationId);
            if (terminalTable)
            {
                select maxof(ReplicationCounter) from posBatchTable
                where posBatchTable.TerminalId == terminalTable.TerminalId;
            }
        }
    }

    return posBatchTable.ReplicationCounter;
}



public void setMaxReplicationCounter(RetailConnDistributionLocationId _locationId, RetailReplicationCounter _counter)
{
    RetailPosBatchTable  posBatchTable;
    RetailTerminalTable terminalTable;

    if (_locationId)
    {
        if (RetailStoreTable::find(_locationId))
        {
            ttsbegin;

            while select forupdate posBatchTable
            where posBatchTable.StoreId == _locationId
            && posBatchTable.ReplicationCounter >= _counter
            {
                posBatchTable.ReplicationCounter = _counter;
                posBatchTable.update();
            }

            ttscommit;
        }
        else
        {
            terminalTable = RetailTerminalTable::find(_locationId);
            if (terminalTable)
            {
                ttsbegin;

                while select forupdate posBatchTable
                where posBatchTable.TerminalId == terminalTable.TerminalId
                && posBatchTable.ReplicationCounter >= _counter
                {
                    posBatchTable.ReplicationCounter = _counter;
                    posBatchTable.update();
                }

                ttscommit;
            }
        }
    }
}



Replace the RetailPosBatchTable   with your table name.

4. Go to Retail ->Setup ->Retail Scheduler -> Distribution Location :
Select your distribution Location and click on Location table , select the table for which you want to pull data,click on Location fields , now you can add fields either Manually or you can use function button provided.
[Make sure to select only those fields which are available in corresponding AX table,else AX will throw error , filed in not available in table]
5. Now go to Retail ->Setup ->Retail Scheduler ->Scheduler subjob
Create a new subjob :

And set the important fields as below :

6.Click on Create TempDBStaging table , which will make a temporary table TableX .
TableX is being used by AX to hold staging data.
7. Now either you can create a new P-job or you can add this sub job in existing P-job.

Run the P-job and data will be pulled to AX from Store
[Off-course you should have retail settings in Place :) ]









Buf2Buf() vs Data() method

Hi all,
while creating a duplicate/replica of a record , generally we use table.data() method , in place of passing each  field one by one. The only issue with data() method is it copies the system fields as well , and hence if we are inserting data across companies , we can not use data() method.

So what should be solution for this, AX also provides one more generic method Buf2Buf(SourceRecord,TargetRecord) , the only difference between Buf2Buf() and data() method is that Buf2Buf() does not copy system fields.

Hence for intercompany insert of data , we should use Buf2Buf() method with changeCompany() method().


thanks,