Showing posts with label AX. Show all posts
Showing posts with label AX. Show all posts

Tuesday, May 21, 2019

Post Sales Order Confirmation X++

Generate post sales order confirmation from X++

SalesTable salesTable = SalesTable::find(“000747”);
SalesFormLetter salesFormLetter;

salesFormLetter = SalesFormLetter::construct(DocumentStatus::Confirmation);
salesFormLetter.update(salesTable, systemDateGet(), SalesUpdate::All);

Wednesday, April 17, 2019

Job To Cancel Reminder Qty of Purchase Orders from CSV File

static void PO_CancelReminder(Args _args)
{
    PurchLine       _PurchLine;
    Qty             _qty;
    PurchId         _PurchId;
    Dialog          dialog;
    Filename        filenameWarehouse,filenameItem;
    DialogField     dialogFilename;
    container       conFilter = ["Comma Seperated Value .txt ", "*.csv"];
    FilenameOpen    filename;
    Container       record;
    #File
    IO  iO;
    boolean first = true;
    dialog = new dialog();
    dialog.caption("Select PO File");
    dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen));
    dialog.filenameLookupFilter(conFilter);
    dialog.run();
    if(dialog.closedOk())
    {
        filenameWarehouse = dialogFileName.value();
        iO = new CommaTextIo(filenameWarehouse,#IO_Read);
        if(!iO || iO.status() != IO_Status::Ok)
            throw error("@SYS19358");
       
        startLengthyOperation();
        while(iO.status()  == IO_Status::Ok)
        {
            record = iO.read();
            if(conPeek(record,1)&&conPeek(record,1) != '')
            {
                _PurchId = conPeek(record,1);
                while select forupdate * from _PurchLine where _PurchLine.PurchId == _PurchId // _PurchLine.RemainInventPhysical > 0
                {
                    if(_PurchLine.RemainPurchPhysical > 0)
                    {
                        ttsBegin;
                        _Qty = _PurchLine.RemainPurchPhysical;
                        _PurchLine.RemainPurchPhysical = 0;
                        _PurchLine.RemainInventPhysical = 0;
                        if(_PurchLine.validateWrite())
                        {
                            InterCompanyUpdateRemPhys::synchronize(_PurchLine,
                                                           _qty,
                                                           _qty);
                            _PurchLine.write();
                            info(strFmt("PO# %1 Line# %2 Item# %3 C.Qty %4",_PurchLine.PurchId,_PurchLine.LineNumber,_PurchLine.ItemId,_qty));
                        }
                        ttsCommit;
                    }
       
                }
            }
        }
    }
   
}


Saturday, March 30, 2019

AX2012 Print Dynamic Parameters

in addition to parameters specified in data contracts, reports can also use queries. It’s very handy, because users can specify filters and sorting in exactly the same way as they’re used to from other places in Dynamics AX, they can use query expressions and so on.

A relative common request is printing parameter values on the report itself. It’s easy with parameters defined in data contracts – an expression like =Parameters!UsersToInclude.Value will do the job. But the same approach doesn’t work with dynamic parameters (that’s how query parameters get represented in SSRS).
I recommend the following approach. Use a report data provider class – very often, it’s already in place. Add a new data table to hold information about query ranges and expose it to the report. I’m using an existing table, TmpSysQuery, so we don’t have to discuss the design of the table. In processReport(), we extract ranges from the current query and save them to our temporary table.


class LedgerJournalPostControlDP extends SRSReportDataProviderBase
{
   
    TmpSysQuery tmpSysQuery;
}
 
[SRSReportDataSetAttribute(tablestr(TmpSysQuery))]
public TmpSysQuery getTmpSysQuery()
{
    select tmpSysQuery;
    return tmpSysQuery;
}
 
public void processReport()
{
   
    tmpSysQuery = MyQueryUtils::rangesToTable(this.query());
}

public static TmpSysQuery rangesToTable(Query _query)
{
    QueryBuildDataSource    qbds;
    QueryBuildRange         queryBuildRange;
    TmpSysQuery             tmpSysQuery;
    LabelType               tableLabel;
    int                     occurrence;
    int                     dataSourceNo;
    int                     i;
 
    if (!_query)
    {
        return tmpSysQuery;
    }
 
    for (dataSourceNo = 1; dataSourceNo <= _query.dataSourceCount(); dataSourceNo++)
    {
        qbds = _query.dataSourceNo(dataSourceNo);
        if (qbds.enabled())
        {
            occurrence = SysQuery::tableOccurrence(_query, qbds.table(), dataSourceNo);
            tableLabel = tableId2pname(qbds.table()) + SysQuery::tableOccurrenceText(occurrence);
 
            for (i = 1; i <= qbds.rangeCount(); i++)
            {
                queryBuildRange = qbds.range(i);
 
                if (queryBuildRange.value() && queryBuildRange.status() != RangeStatus::Hidden)
                {
                    tmpSysQuery.clear();
                    tmpSysQuery.DataSourceNo = qbds.uniqueId();
                    tmpSysQuery.TableLabel   = tableLabel;
                    tmpSysQuery.FieldLabel   = fieldId2pname(qbds.table(), queryBuildRange.field());
                    tmpSysQuery.RangeValue   = queryBuildRange.value();
                    tmpSysQuery.insert();
                }
            }
        }
    }
 
    return tmpSysQuery;
}

Then we add a new data set in our report and show query ranges in a tablix in exactly the same way as other data:


Saturday, October 22, 2016

Using AOT Query object from X++

1) Create a AOT Query Object as your requirement.
2) Create a Job and paste the below code to check the Query Object.
 static void ExecuteAOTQuery(Args _args)  
 {  
 QueryRun queryRun;  
 Counter totalRecords;  
 ;  
 queryRun = new QueryRun(queryStr(CreatedAOTQueryName));  
 if (queryRun.prompt())  
 {  
 while (queryRun.next())  
 {  
 totalRecords++;  
 }  
 }  
 info(strFmt(“Total Records : %1”, totalRecords));  
 }