Monday, 18 March 2019

lookup - use method in lookup and



Query       query = new Query();
    QueryBuildDataSource    qbds,qbds1;
    //QueryBuildRange         qbr;
    SysTableLookup          sysTableLookUp; VendTable VendTable ;
    sysTableLookUp = SysTableLookup::newParameters(tableNum(VendTable),_control);
    //qbds = query.addDataSource(tableNum(VendorView));     
    //qbr = qbds.addRange(fieldNum(VendorView, AccountNum));
    //qbr.value(SysQuery::valueNotEmptyString());
    //
    //sysTableLookUp.addLookupfield(fieldNum(VendorView,AccountNum));
    //sysTableLookup.addSelectionField(fieldNum(VendorView,AccountNum));
    //sysTableLookUp.addLookupfield(fieldNum(VendorView,Name));
    //
    //sysTableLookUp.parmQuery(query);
    //sysTableLookUp.performFormLookup();
   
    qbds = query.addDataSource(tableNum(VendTable));
   //qbds1  = qbds.addDataSource(tableNum(DirPartyTable));
   //Qbds1.addLink(fieldNum(VendTable, Party), fieldNum(DirPartyTable, RecId));
   //Qbds1.joinMode(JoinMode::InnerJoin);
   //Qbds1.relations(true);
 
     
   sysTableLookup.parmQuery(query);
   sysTableLookup.addLookupfield(fieldNum(VendTable, AccountNum),true); 
   sysTableLookup.addLookupfield(fieldNum(VendTable, party));
   sysTableLookup.performFormLookup(); 

Tuesday, 12 March 2019

Edit field except 1 or more fileds in DataSource - AX 2012

Edit field except 1 or more fileds in DataSource -

allowEditFieldsOnFormDS_W(BankChequeTable_DS, false);

    BankChequeTable_DS.object(fieldNum(BankChequeTable, chequeHandoverTo)).allowEdit(true);
    BankChequeTable_DS.object(fieldNum(BankChequeTable,ChequeHandoverDate)).allowEdit(true);

Monday, 11 February 2019

import sales forecast using CSV file ax 2012

import sales forecast using CSV file ax 2012


public void ImportDate()
{
    #File
     Dialog          dialog;
    Filename         filename;
    DialogField      dialogFilename;

    //To filter the files while selecting
    container    conFilter = ["Comma Seperated Value .txt ", "*.csv"];
    IO                  iO;
    FilenameOpen        filenameOpen;
    Container           record;
    ForecastSales       forecastSales;
    ForecastModel       forecastModel;
    CustTable           custTable;
    InventTable         inventTable;
    InventDim           inventDim,inventDimLoc;
    InventItemGroup     inventItemGroup;
    InventItemPrice     inventItemPrice;
    InventTableModule   inventTableModule;

    DefaultDimensionView   defaultDimensionView;
    boolean             first = true;
    RecId       dd;
    //name dcl
    ForecastModelHeadId  ModelId;
    str                  StartDate;
    str                 itemgroup,SalesUnit;
    real                 priceunit,costprice;
    CustAccount          custAccountId;
    SalesQty             SalesQty;
    ItemId               ItemId;
    CustGroupId          custGroup;
    InventSiteId        InventSiteId;
    RecId               recIdDefaultDimension;
    CustCurrencyCode     Currency;
    HcmPersonnelNumberId  hcmPersonnelNumberId;
    DF_Uploading projDimUpload = new DF_Uploading();
    CostPrice             cp;
    InventLocationId    inventLocationId;

    dialog = new dialog();
    dialog.caption("Select File For forecastSales Master Import");
    dialogFilename = dialog.addField(extendedTypeStr(FilenameOpen));
    //To filter the files while selecting
    dialog.filenameLookupFilter(conFilter);
    dialog.run();


     if(dialog.closedOk())
        {
         filename = dialogFileName.value();
          //info(strFmt("%1", filename));
        }

    iO = new CommaTextIo(filename,#IO_Read);
    if (! iO || iO.status() != IO_Status::Ok)
        {
        throw error("@SYS19358");
        }

    while (iO.status() == IO_Status::Ok)
    {
    record = iO.read();// To read file
        if (record)
        {
        if (first)  //To skip header
        {
        first = false;
        }
       else
        {
            ModelId         = conpeek(record, 1);
            StartDate       = conpeek(record, 2);
            custAccountId   = conpeek(record, 3);
            ItemId          = conpeek(record, 4);
            SalesQty        = conpeek(record, 5);
            priceunit       = conpeek(record, 6);
           // InventSiteId    = conpeek(record, 7);
            hcmPersonnelNumberId = conpeek(record, 8);
            cp       = conpeek(record, 9);
            inventLocationId =  conpeek(record, 10);

            select forecastModel where forecastModel.ModelId == ModelId;

            custGroup = CustTable::find(custAccountId).CustGroup;
           Currency  = CustTable::find(custAccountId).Currency;
           select InventTable where InventTable.ItemId == ItemId;
             //priceunit = any2real(InventTable.());
            SalesUnit = any2str(InventTable.salesUnitId());
            itemgroup = any2str(InventTable.itemGroupId());


            //--> added msk for cost prices

            //select inventItemPrice  order by ActivationDate desc  where inventItemPrice.ItemId ==  ItemId;
            //costprice = inventItemPrice.Price;
//
            InventSiteId = InventTable::find(ItemId).inventInventSiteId();

            select inventDim where inventDim.InventSiteId  == InventSiteId;
            inventDim.InventLocationId =inventLocationId;

            inventDimLoc = InventDim::findOrCreate(inventDim);
//
            //if(costprice == 0 )
            //{
           //select  inventTableModule where inventTableModule.ModuleType == ModuleInventPurchSales::Invent && inventTableModule.ItemId == ItemId;
            //costprice= inventTableModule.Price;
            //}
             //--> added msk for cost prices  end

            forecastSales.Active         =NoYes::Yes;
            forecastSales.ModelId        = ModelId;
            forecastSales.StartDate      = str2Date(StartDate,123);
            forecastSales.CustAccountId  = custAccountId;
            forecastSales.CustGroupId    = custGroup;
            forecastSales.ItemId         = ItemId;
            forecastSales.ItemGroupId    = itemgroup;

            //forecastSales.DefaultDimension  =dd ;//defaultDimensionView.DefaultDimension;
            forecastSales.Currency       = Currency;
            forecastSales.PriceUnit      = 1;
            forecastSales.Comment        = InventTable.ProductName;
            forecastSales.InventDimId    = inventDimLoc.inventDimId;
            forecastSales.CostPrice     =    cp;//costprice;
            forecastSales.SalesUnitId    = SalesUnit;
            forecastSales.SalesQty       = SalesQty;
            forecastSales.InventQty      = SalesQty;

            forecastSales.SalesPrice    = priceunit;

            forecastSales.Amount       =  priceunit * SalesQty;

            forecastSales.insert();

         projDimUpload.importProjDim(hcmPersonnelNumberId,forecastSales.CustAccountId);

        }

        }
    }

 info("Record insert successfully");
}

Monday, 28 January 2019

select marked records on the form and get terms of payment days

select marked records on the form and get terms of payment days

for(custInvoiceJourLoc = CustInvoiceJour_ds.getFirst(true) ? CustInvoiceJour_ds.getFirst(true) : CustInvoiceJour_ds.cursor(); custInvoiceJourLoc; custInvoiceJourLoc = CustInvoiceJour_ds.getNext())
    {
        select custTransOpen
            join custTrans where custTransOpen.AccountNum == custTrans.AccountNum
            && custTransOpen.RefRecId == custTrans.RecId
            && custTrans.Invoice == custInvoiceJourLoc.InvoiceId
            && custTrans.AccountNum == custInvoiceJourLoc.InvoiceAccount
            && custTrans.TransDate == custInvoiceJourLoc.InvoiceDate
            && custTrans.Voucher == custInvoiceJourLoc.LedgerVoucher;

        salesTable = SalesTable::find(custInvoiceJourLoc.SalesId);
       custDueDate = PaymTerm::find(salesTable.Payment).due(today());

        info(strFmt("%1 , %2 , %3 %4", custInvoiceJourLoc.OrderAccount,custInvoiceJourLoc.LedgerVoucher,custTransOpen.DueDate,custDueDate));
    }

Monday, 17 December 2018

Get Approver name from workflow history - ax 2012

Get Approver name from workflow history




public display Name displayApproverName()
{
    WorkflowTrackingTable           workflowTrackingTable;
    WorkflowTrackingStatusTable     workflowTrackingStatusTable;
    WorkflowTrackingCommentTable    workflowTrackingCommentTable;
    WorkflowTrackingWorkItem        workflowTrackingWorkItem;
    WorkflowWorkItemTable           workflowWorkItemTable;

    select ContextCompanyId, ContextTableId, ContextRecId from workflowTrackingStatusTable
        where workflowTrackingStatusTable.ContextCompanyId    == curext()
           && workflowTrackingStatusTable.ContextTableId      == this.TableId
           && workflowTrackingStatusTable.ContextRecId        == this.RecId
        join firstonly TrackingId, CreatedDateTime,user from workflowTrackingTable order by CreatedDateTime desc
            where workflowTrackingTable.WorkflowTrackingStatusTable == workflowTrackingStatusTable.RecId
        join workflowTrackingWorkItem where workflowTrackingWorkItem.WorkflowTrackingTable == workflowTrackingTable.RecId
        join workflowWorkItemTable where workflowTrackingWorkItem.WorkItemId == workflowWorkItemTable.Id  ;

    return workflowWorkItemTable.userName();
}

For more information about this error navigate to the report server on the local server machine, or enable remote errors - ssrs report ax 2012

For more information about this error navigate to the report server on the local server machine, or enable remote errors - generating ssrs report - ax 2012.


Go to SQL server management studio (ssms).

connect to Reporting server - Right Click - select properties

Navigate to Advance - change property 'EnableRemoteError' to 'True'.




Tuesday, 11 December 2018

use AOT query in code


use AOT query in code
static void Job10(Args _args)
{

    CustInvoiceJour custInvoiceJour;
    Query           query = new Query(queryStr (InventJournalTrans)); // Query name.
    QueryRun        qr;
    QueryBuildRange qbr;
    InventJournalTrans inventJournalTrans;
    MainAccount mA;
    DimensionAttributeValueCombination dimensionAttributeValueCombination;
    HcmWorker hcmWorker;
    JournalError    journalError;
    InventDim   inventDim;
    // Find the InvoiceDate range on AOT Query.
    qbr = query.dataSourceTable( tablenum (InventJournalTrans))
            .findRange( fieldNum (InventJournalTrans, JournalId));

    // We can check if the query range does exist, if not, we can create it.
    if (!qbr)
    {
        qbr = query.dataSourceTable( tableNum (InventJournalTrans))
            .addRange( fieldNum (InventJournalTrans, JournalId));
    }

    // Assigning query range value.
    qbr.value('IJN006806');


    // Executing our query.
    qr = new QueryRun(query);

    // Looping through query results.
    while (qr.next())
    {
        // Assinging query results to table buffer.
        inventJournalTrans = qr.get(tableNum(InventJournalTrans));
        mA = qr.get(tableNum(MainAccount));
        dimensionAttributeValueCombination  = qr.get(tableNum(DimensionAttributeValueCombination));
        inventDim = qr.get(tableNum(InventDim));
        // Showing results.
        info( strFmt ('%1 - %2 - %3' , inventJournalTrans.JournalId,
                                    dimensionAttributeValueCombination.RecId,
                                    inventDim.RecId));
    }