Monday, 17 December 2018

file movement in batch (find and replace) in batch find and delete duplicate file

there might be a duplicate file while moving to destination location in that case ,


public boolean getFileExists(filepath _fileName)
{
   System.IO.FileInfo   fileInfo;
   new InteropPermission(InteropKind::ClrInterop).assert();
   fileInfo = new System.IO.FileInfo(_fileName);
   return fileInfo.get_Exists();

}


    if(this.getFileExists(strFmt('%1%2%3', DestinationPathFolder, fName, fType)) == true)
    {
        System.IO.File::Delete(strFmt('%1%2%3', DestinationPathFolder, fName, fType));
    }

Tuesday, 13 November 2018

disable/enabled based on the radio formgroupcontrol

I have a group "All" and frameoption button is "Radio" now based on this formgroupcontrol i want to disable and enable another group  in the active method of datasource which is not happening.

if (All.optionValue() == 1)
   {
     Group4.allowEdit(false);
   }
   else
   {
       Group4.allowEdit(true);
   }

Thursday, 8 November 2018

multiple SO invoice invoicing with single invoice ID

static void Job217(Args _args)
{
    SalesFormLetter salesFormLetter;
    QueryRun queryRun;
    Query query;
    str strSalesTable = "TSSO00001979, TSSO00001982";// "000630,000631,000643";
    int64  salesline1,salesline2;
    str saleslines;
   
    SalesTable salesTable;
    SalesLine salesLine;
    ;
    //TSSO00001961
    //TSt00000199
   
    select salesLine where salesLine.SalesId == "TSSO00001961";
    salesline1 = salesLine.RecId;
    salesLine.clear();
   
    select salesLine where salesLine.SalesId == "TSt00000199";
   
    salesline2 = salesLine.RecId;
    saleslines = strFmt("%1,%2",salesline1,salesline2);
   
   
    salesFormLetter = SalesFormLetter::construct(DocumentStatus::Invoice);

    query = new Query(QueryStr(SalesUpdate));
    //query.dataSourceTable(tablenum(SalesTable)).addRange(fieldnum(SalesTable, SalesId)).value(strSalesTable);
   
    query.dataSourceTable(tablenum(salesLine)).addRange(fieldnum(salesLine, RecId)).value(saleslines);
    queryRun = new QueryRun(query);

    salesFormLetter.chooseLinesQuery(queryRun);
    salesFormLetter.transDate(systemdateget());
    salesFormLetter.specQty(SalesUpdate::All);
   
    salesFormLetter.chooseLines(); 

    salesFormLetter.run();
   
    info("done");

}

Wednesday, 31 October 2018

registration of sales return order by x++

public void createRegisterline(SalesTable _salestable)
{
    Integer                                 lastRec = 0;
    SalesId                                 oldSalesId;
    inventTrans                             inventTrans;
    SalesFormLetter                         salesFormLetter;
    inventTransOrigin                       inventTransOrigin;
    TradeOrderLineRegister                  tradeOrderlineRegister;
    SON_SalesReturnOrderLineRegister        salesReturnOrderLineRegister;
    InventTransWMS_Register                 inventTransWMS_register;
    TmpInventTransWMS                       TmpInventTransWMS;
    SalesLine                               salesLineReg;
    ReturnDispositionCode                   returnDispositionCode;
    SON_IPB49_InventStkTransHeader          headerTable,headerTableLoc;
    Description255                          errorMsg;

    Args                                    args = new Args();

    try
    {
        ttsBegin;
        select firstOnly * from returnDispositionCode
            where returnDispositionCode.DispositionAction == DispositionAction::Credit;

        while  select forUpdate salesLineReg
            where _salestable.SalesId  == salesLineReg.SalesId
            && _salestable.SalesType == SalesType::ReturnItem
        {
            try
            {

                args.record(salesLineReg);

                tradeOrderLineRegister = SON_SalesReturnOrderLineRegister::construct();
                tradeOrderLineRegister.parmArgs(args);
                tradeOrderLineRegister.init();
                salesReturnOrderLineRegister = tradeOrderLineRegister;
                salesReturnOrderLineRegister.runPreSuper();

                //update returnDisposioncode
                salesLineReg.ReturnDispositionCodeId = returnDispositionCode.DispositionCodeId;
                salesLineReg.update();

                select firstOnly crossCompany inventTrans
                    join RecId,InventTransId from inventTransOrigin
                        where inventTransOrigin.InventTransId == salesLineReg.InventTransId
                        && inventTrans.InventTransOrigin == inventTransOrigin.RecId;

                inventTransWMS_register = inventTransWMS_register::newStandard(tmpInventTransWMS);
                tmpInventTransWMS.clear();
                tmpInventTransWMS.initFromInventTrans(inventTrans);
                tmpInventTransWMS.InventDimId = inventTrans.InventDimId;
                tmpInventTransWMS.insert();
                inventTransWMS_register.writeTmpInventTransWMS(tmpInventTransWMS,
                                                               inventTrans,
                                                               inventTrans.inventDim());
                inventTransWMS_register.updateInvent(salesLineReg);
            }
            catch
            {
                continue;
            }
        }


        ttsCommit;
    }
    catch
    {

    }
}

sales return by x++

public void createReturnOrder(PurchTable _purchtable)
{
    SalesLine                           salesLine;
    SalesTable                          salesTable, salesTableloc;
    SalesParameters                     salesParameters;
    ReturnPeriodOfValidity              periodofValid;
    SON_AttachmentELMOInvoice   attachmentELMOInvoiceloc, attachmentELMOSumQty,SON_AttachmentELMOInvoice;
    SON_ELMOSummaryInvoice  SON_ELMOSummaryInvoice;
    AxSalesTable            axsalesTable;
    AxSalesLine axSalesLine;
    SalesFormLetter salesFormLetter;
    PurchTable PurchTableLocal;
    PurchFormLetter purchFormLetter;
    SON_ELMOISalesTable SON_ELMOISalesTable;
    SON_DeliveryNote    SON_DeliveryNote;

    try
    {
        salesParameters = SalesParameters::find();
        periodofValid   = salesParameters.ReturnPeriodOfValidity;

        select SON_ELMOSummaryInvoice  where SON_ELMOSummaryInvoice.AXPONumber == _purchtable.PurchId;

        while select SON_AttachmentELMOInvoice group by StoreID
            where SON_AttachmentELMOInvoice.SummaryInvoiceNumber == SON_ELMOSummaryInvoice.InvoiceNumber
                && SON_AttachmentELMOInvoice.InvoiceDate == SON_ELMOSummaryInvoice.InvoiceDate
        {

            //insert sales table
            {
                salesParameters = SalesParameters::find();
                periodofValid   = salesParameters.ReturnPeriodOfValidity;
                salesTable.SON_StoreId = SON_AttachmentELMOInvoice.StoreID;
                salesTable.SON_VendAccount = _purchTable.OrderAccount;
                salesTable.SON_PBSalesOrder=NoYes::Yes;
                salesTable.CustAccount             = RetailStoreTable::find(SON_AttachmentELMOInvoice.StoreID).SON_DefaultCustAccount;
                salesTable.InvoiceAccount          = salesTable.CustAccount;
                salesTable.SalesId                 = NumberSeq::newGetNum(SalesParameters::numRefSalesId()).num();
                salesTable.ReturnItemNum           = salesTable.SalesId;
                salesTable.SalesType               = SalesType::ReturnItem;
                salesTable.ReturnStatus            = ReturnStatusHeader::Created;
                salesTable.DeliveryDateControlType = SalesDeliveryDateControlType::None;
                salesTable.SON_InvStkTrans         = NoYes::Yes;
                salesTable.ShippingDateRequested   = today();
                salesTable.ShippingDateConfirmed   = salesTable.ShippingDateRequested;
                salesTable.ReceiptDateConfirmed    = salesTable.ShippingDateRequested;
                salesTable.ReceiptDateRequested    = salesTable.ShippingDateRequested;

                salesTable.initFromCustTable();
                salesTable.ReturnDeadline          = salesTable.ShippingDateRequested;
                salesTable.InventLocationId        = InventParameters::find().SON_DD;
                salesTable.InventSiteId            = InventLocation::find(salesTable.InventLocationId).InventSiteId;
                salesTable.DefaultDimension        = SON_InventStockTransfer::getStoreCostCenter(salesTable.SON_StoreId);
                axsalesTable = AxSalesTable::newSalesTable(salesTable);
                axsalesTable.parmSON_StoreOrderType(SON_StoreOrderType::ELMO);
                axsalesTable.doSave();

                SON_ELMOISalesTable.clear();
                SON_ELMOISalesTable.PurchId = _purchTable.PurchId;
                SON_ELMOISalesTable.SalesId = salesTable.SalesId;
                SON_ELMOISalesTable.CustAccount = salesTable.CustAccount;
                SON_ELMOISalesTable.insert();

            }

            //insert lines
            while select attachmentELMOInvoiceloc where attachmentELMOInvoiceloc.StoreID == SON_AttachmentELMOInvoice.StoreID
                && attachmentELMOInvoiceloc.SummaryInvoiceNumber == SON_ELMOSummaryInvoice.InvoiceNumber
                && attachmentELMOInvoiceloc.InvoiceDate == SON_ELMOSummaryInvoice.InvoiceDate
                {
                    //insert saleslines
                    salesLine.clear();
                    salesLine.initValue();
                    salesLine.initFromSalesTable(salesTable);
                    salesLine.initFromCustTable();
                    salesLine.initFromSalesTable(salesTable);
                    salesLine.ItemId            = this.GetEANCode(attachmentELMOInvoiceloc);
                    salesLine.SON_EANCode       = attachmentELMOInvoiceloc.EANCode;
                    salesLine.SalesUnit         = InventTableModule::find(salesLine.ItemId, ModuleInventPurchSales::Invent).UnitId;
                    salesLine.DefaultDimension  = SON_InventStockTransfer::salesLineDefaultDimension(salesTable, InventTable::find(salesLine.ItemId));
                    salesLine.SalesQty          = attachmentELMOInvoiceloc.InvoicedQty;
                    salesLine.ExpectedRetQty    = salesLine.SalesQty;
                    salesLine.LineAmount        = attachmentELMOInvoiceloc.VendorInvoiceAmt;
                    salesLine.SON_deliveryNote  = attachmentELMOInvoiceloc.DeliveryNote;
                    axSalesLine                 = AxSalesLine::newSalesLine(salesLine);
                    axSalesLine.Save();

                }//while select attachmentELMOInvoiceloc

                attachmentELMOInvoiceloc.clear();

                select firstOnly attachmentELMOInvoiceloc  where attachmentELMOInvoiceloc.SummaryInvoiceNumber == SON_ELMOSummaryInvoice.InvoiceNumber
                && attachmentELMOInvoiceloc.InvoiceDate == SON_ELMOSummaryInvoice.InvoiceDate;

                // for client testing
                delete_from SON_DeliveryNote;
                SON_DeliveryNote.DeliveryNote = attachmentELMOInvoiceloc.DeliveryNote;
                SON_DeliveryNote.insert();
                // for client testing

                ttsBegin;
                select forUpdate salesTableloc  where salesTableloc.SalesId == salesTable.SalesId;
                salesTableloc.SON_deliveryNote = attachmentELMOInvoiceloc.DeliveryNote;
                salesTableloc.doUpdate();
                ttsCommit;

            salesFormLetter = SalesFormLetter::construct(DocumentStatus::Confirmation);
            salesFormLetter.update(SalesTable::find(salesTable.SalesId), today());
            changeCompany (salesTable.InterCompanyCompanyId)
            {
                select  crossCompany  PurchTableLocal
                where PurchTableLocal.dataAreaId  == salesTable.InterCompanyCompanyId
                &&    PurchTableLocal.PurchId == salesTable.InterCompanyPurchId;

                // PO confirmation
                purchFormLetter = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
                purchFormLetter.update(PurchTableLocal, strFmt("POConfirm_%1",PurchTableLocal.PurchId));
                info(strFmt("purchase order %1 confirmed succssfully.",PurchTableLocal.PurchId));

                // PO packing slip
                // purchFormLetter = PurchFormLetter::construct(DocumentStatus::PackingSlip);
                // purchFormLetter.update(PurchTableLocal, strFmt("POPack_%1", PurchTableLocal.PurchId));
                // this.partialPOPacking(PurchTableLocal.PurchId);
                // info(strFmt("purchase order %1 packing slip posted succssfully.",PurchTableLocal.PurchId));

            }//change company
            this.createRegisterline(salesTable);
            this.partialSOPacking(salesTable, _purchTable );

        }
    }
    catch
    {

         warning("error found while creating sales order for purchase order");
    }

  //  return isSuccess;
}

Wednesday, 10 October 2018

code for posting partial packing slip for intercompany PO

say we have a sales order and we have created  a partial packing slip for the sales order  and want to  post packing slip for the relevant purchline with the same  packing slip.


static void Job203(Args _args)
{   

    CustPackingSlipJour CustPackingSlipJour;


    select CustPackingSlipJour  where CustPackingSlipJour.SalesId == "00001283"
    && CustPackingSlipJour.PackingSlipId == "TT43953408";
    if(CustPackingSlipJour)
    {
        CustPackingSlipJour::interCompanyUpdateIL([custPackingSlipJour]);
    }

    info("done");

}

Monday, 24 September 2018

putting debugger in visual studio in ax 2012

some times we need to debug the batch job in ax 2012 so  we need to attach the process

which is as given below:


Thursday, 13 September 2018

get VAT percentage of purchase line

static void purchsalestax(Args _args)
{
    TaxOnItem       TaxOnItem;
    TaxGroupData    TaxGroupData;
    real            TaxAmount;
    TaxValue        TaxValue;
    PurchLine       PurchLine;
    ;

    select firstOnly PurchLine where PurchLine.PurchId == '00002622'
    && PurchLine.LineNumber == 1;   

    if(PurchLine.TaxItemGroup && PurchLine.TaxGroup && PurchLine.LineAmount != 0)
    {
        while select TaxOnItem
        where TaxOnItem.TaxItemGroup == PurchLine.TaxItemGroup
        join TaxGroupData
        where TaxGroupData.TaxGroup == PurchLine.TaxGroup
        && TaxGroupData.TaxCode  == TaxOnItem.TaxCode
        {
            if(TaxGroupData)
            {
                TaxValue  =  TaxData::find(TaxOnItem.TaxCode, Systemdateget(), 0).TaxValue;
                TaxAmount = (PurchLine.LineAmount * TaxValue) / 100;
                info(strFmt("Rate = %1, Tax Amount = %2",TaxValue,TaxAmount));

            }
        }
       
    }


}

Tuesday, 11 September 2018

creating DPK file and saving the changes


Creating the DPK 
  1. In CoreXT type sdp pack -c <changelist number> <file name>.dpk, for example: 
sdp pack -c 6959294 TMSProjects.dpk 

If the -c parameter is not used, then the default change list is used. 


  1. The file is located in the root folder for the enlistment, for example: 
E:\RainMain\TMSProjects.dpk 

  1. Copy the file on your own machine or some place on which it will not get deleted. 

Applying the DPK 
  1. Copy the file to the root folder of the enlistment (on the other machine), for example: 
E:\RainMain 

  1. In CoreXT type sdp apply <file name>.dpk -a, for example: 
sdp apply TMSProjects.dpk -a 


If you open SDB, you can see that a new change list has been created. 

  1. In CoreXT type sd resolve -a and resolve the co

intercompany PO multiple product receipt by x++

public void processStampICPO(PackingSlipId _deliveryNote,                             Transdate _deliverydate,                             ...