Wednesday 18 December 2019

intercompany PO multiple product receipt by x++

public void processStampICPO(PackingSlipId _deliveryNote,
                            Transdate _deliverydate,
                            InterCompanyCompanyId _dataAreaID,
                            custPackingSlipJour _custPackingSlipJour)
{
    SalesTable              salesTable;
    CustPackingSlipJour     custPackingSlipJour =_custPackingSlipJour;
    CustPackingSlipTrans    custPackingSlipTrans;
    PurchLine               purchLine;
    int                     i,j;
    boolean                 isPosted;
    PurchId                 purchId;
    utcDateTime             currentDatetime;
    date                    currentDate;
    SON_InterCompanyPurchView   interPurchTable;
    InventTransId           interInventTrans;

    //currentDatetime = DateTimeUtil::utcNow();
    //currentDatetime = DateTimeUtil::applyTimeZoneOffset(currentDatetime,DateTimeUtil::getUserPreferredTimeZone());
    //currentDate     = DateTimeUtil::date(currentDatetime);
//
    //while select forUpdate SON_DDDeliveryNote,DeliveryDate,InterCompanyCompanyId,
    //SON_IsIntercompanyPOPosted,PackingSlipId from custPackingSlipJour
        //where custPackingSlipJour.SON_IsIntercompanyPOPosted == NoYes::No
        //&& custPackingSlipJour.SON_DDDeliveryNote != ''
        //&& custPackingSlipJour.DeliveryDate <= currentDate
    //join SalesId,SalesStatus from salesTable
        //where salesTable.SalesId == custPackingSlipJour.SalesId
        //&& salesTable.SalesStatus != SalesStatus::Invoiced
        //&& salesTable.SalesStatus != SalesStatus::Canceled
    //join InterCompanySalesId,PurchStatus from interPurchTable
        //where interPurchTable.InterCompanySalesId == salesTable.SalesId
        //&& interPurchTable.PurchStatus == PurchStatus::Backorder

    {
        //deliveryNote = custPackingSlipJour.SON_DDDeliveryNote;
        //deliveryDate = custPackingSlipJour.DeliveryDate;
        //interCompany = custPackingSlipJour.InterCompanyCompanyId;

       // custPackingSlipJour as _custPackingSlipJour;

        deliveryNote = _deliveryNote;
        deliveryDate = _deliverydate;
        interCompany = _dataAreaID;


        if(interCompany == '0001')
        {
            while select InterCompanyInventTransId,Qty from custPackingSlipTrans
                where custPackingSlipTrans.PackingSlipId == custPackingSlipJour.PackingSlipId
            {
                purchLine.clear();
                select forUpdate * from purchLine
                    where purchLine.InventTransId == custPackingSlipTrans.InterCompanyInventTransId;
                if(purchLine)
                {
                    ttsBegin;
                    purchLine.PurchReceivedNow = custPackingSlipTrans.Qty;
                    purchLine.setInventReceivedNow();
                    purchLine.doUpdate();
                    ttsCommit;
                    purchId = purchLine.PurchId;
                }

            }
        }
        else
        {
            while select crossCompany InventTransId,Qty from custPackingSlipTrans
                where custPackingSlipTrans.PackingSlipId == custPackingSlipJour.PackingSlipId
            {
                interInventTrans = custPackingSlipTrans.InventTransId;

                select forUpdate  crossCompany * from purchLine
                    where purchLine.InterCompanyInventTransId == interInventTrans
                        && purchLine.PurchStatus == PurchStatus::Backorder;
                if(purchLine)
                {
                    changeCompany(purchLine.dataAreaId)
                    {
                        ttsBegin;
                        purchLine.PurchReceivedNow = custPackingSlipTrans.Qty;
                        purchLine.setInventReceivedNow();
                        purchLine.doUpdate();
                        ttsCommit;
                    }
                    purchId = purchLine.PurchId;
                }
            }
        }

        isPosted = this.postPurchPackingSlip(purchId);//,custPackingSlipJour.InterCompanyCompanyId);
        if(isPosted)
        {
            info(strFmt("@SON2167", custPackingSlipJour.SalesId));
            info(strFmt("@SON2168", custPackingSlipJour.SalesId,purchId));
            ttsBegin;
            custPackingSlipJour.SON_IsIntercompanyPOPosted = NoYes::Yes;
            custPackingSlipJour.doUpdate();
            ttsCommit;
            i++;
        }
        else
        {
            j++;
        }
    }
    //info(strFmt('%1 - ICPO were posted successfully and %2 were failed',i,j));

}

-------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------

public boolean postPurchPackingSlip(PurchId _purchId)
{
    PurchFormLetter purchFormLetter =  PurchFormLetter::construct(DocumentStatus::PackingSlip);
    PurchFormLetter purchFormLetterConfirm;
    PurchParmLine   parmLine;
    PurchTable      purchTableUpdate,purchTable;
    PurchParmTable  purchParmTable;
    PurchId         purchIdError;
    boolean         ret = false;
    VendPackingSlipJour vendPackingSlipJour;
    SON_InterSalesLinesView interSalesLine;

    try
    {

        changeCompany(interCompany)
        {
            //check and get updated date afterchecking fiscal calender and inventory closing
            deliveryDate = this.getinvoicedate(deliveryDate);
            //
            if(purchIdError != _purchId)
            {
                purchTable.clear();
                purchTable = PurchTable::find(_purchId);
                if(purchTable.DocumentState == VersioningDocumentState::Approved)
                {
                    purchFormLetterConfirm = PurchFormLetter::construct(DocumentStatus::PurchaseOrder);
                    purchFormLetterConfirm.update(purchTable,'InterPurchConf_'+purchTable.PurchId);
                }

                purchFormLetter.purchTable(purchTable);
                purchFormLetter.transDate (deliveryDate);
                purchFormLetter.specQty(PurchUpdate::ReceiveNow);

                purchFormLetter.initParmDefault();
                purchFormLetter.initParameters(purchFormLetter.purchParmUpdate(),Printout::After);
                purchFormLetter.initLinesQuery();

                select forUpdate Num from purchParmTable
                    where purchParmTable.ParmId == purchFormLetter.parmId();

                if(purchParmTable)
                {
                    ttsBegin;
                    purchParmTable.Num = deliveryNote;
                    purchParmTable.update();
                    ttsCommit;
                }

                purchFormLetter.run();

                if (purchformletter.parmjournalrecord().tableid == tablenum(vendpackingslipjour))
                {
                    ret = true;
                }
            }
        }
    }
    catch
    {
        this.insertErrorLog(purchTable.InterCompanySalesId,SON_POPackingSlipDD::HasError());
        infolog.clear();
        //info(strFmt('%1',SON_POPackingSlipDD::HasError()));
        purchIdError = purchTable.PurchId;
        ret = false;
        retry;
    }
    return ret;
}

Tuesday 12 November 2019

buf2buf in ax 2012



buf2buf copies all fields except system fields.(intercompany usefull)
data copies every thing including system fields.

static void updatesalesparameter(Args _args)
{

    CompanyInfo CompanyInfo;
    SalesParameters SalesParameters,SalesParameters1375;
    CustParameters  CustParameters,CustParameters1375;
    CustLedger      CustLedger;


   
    changeCompany ('9999')
    {
        select CustParameters1375;
        select SalesParameters1375;
    }
   
    select CompanyInfo  where CompanyInfo.DataArea == "1997"
    && CompanyInfo.SON_Active == NoYes::Yes;
    {
   
        changeCompany(CompanyInfo.DataArea)
        {
            SalesParameters = null;
            CustParameters = null;
            CustLedger = null;
            ttsBegin;

            select forUpdate SalesParameters;
            if(SalesParameters)
            {
                SalesParameters.OrderType = SalesType::Sales;
                SalesParameters.doUpdate();
           
            }
            else
            {
                SalesParameters.clear();
                //SalesParameters.BillOfLading = SalesShipping::None;
                //SalesParameters.OrderType = SalesType::Sales;
                //SalesParameters.BOLfreightChargeTerms = WMSFreightChargeTerms::Prepaid;
                //SalesParameters.BOLfreightCounted = WMSFreightCounted::ByShipper;
                //SalesParameters.BOLFreightedBy = WMSFreightedBy::Carrier;
                //SalesParameters.BOLtrailerLoaded = WMSTrailerLoaded::ByShipper;
                //SalesParameters.CreditNoteDocumentDateControlType_W = DateControlType_W::None;
                //SalesParameters.CreditNoteInvoiceDateControlType_W = DateControlType_W::None;
                //SalesParameters.MCRResourceNum_Acceptable = 3125;
                //SalesParameters.MCRResourceNum_Questionable = 3127;
                //SalesParameters.MCRResourceNum_Unacceptable = 3126;
                //SalesParameters.OrderEntryStatistics = 5;
                //SalesParameters.PromptQty = NoYes::Yes;
                //SalesParameters.QuotationNumOfDaysExpiryDate =30;
                //SalesParameters.QuotationNumOfDaysFollowUpDate =2;
                //SalesParameters.SplitDeliveryPackingSlip = NoYes::Yes;
                //SalesParameters.SplitDeliveryPickingList = NoYes::Yes;
                //SalesParameters.insert();
                buf2buf(SalesParameters1375, SalesParameters);
                SalesParameters.OrderType = SalesType::Sales;
                SalesParameters.insert();
            }
            select CustLedger  where CustLedger.PostingProfile == 'Gen';
            if(!CustLedger)
            {
                CustLedger.initValue();
                CustLedger.PostingProfile = 'Gen';
                CustLedger.insert();
            }
            CustLedger.clear();
            select CustLedger  where CustLedger.PostingProfile == 'Gen';
       
            select forUpdate CustParameters;
            if(CustParameters)
            {
                CustParameters.PostingProfile = CustLedger.PostingProfile;
                CustParameters.doUpdate();
            }
            else
            {
                //CustParameters.clear();
                //CustParameters.PostingProfile = CustLedger.PostingProfile;
                //CustParameters.insert();
                buf2buf(CustParameters1375, CustParameters);
                CustParameters.PostingProfile = CustLedger.PostingProfile;
                CustParameters.insert();
            }

            ttsCommit;
        }
    }

}

Saturday 4 May 2019

chain of command in d 365

create a class 

[ExtensionOf(classStr(SalesLineType))]
final class SalesLineType_Extension
{
    
    
    public void inserting()
    {
       
        CustTable   custTable;
        
        //get customer for evalation of credit rating
        custTable = CustTable::find(salesLine.CustAccount);
 
        if(!custTable.CreditRating)
        {
            info("Customer on sales line has no credit rating!");
        }
 
        // must call next when using Chain of Command pattern
        next inserting();

       
    }

}

first 2 lines are important as it tells it is an extension of which class and suffix should end with _extension

now add sales table form in the project and add as a start up object  and run  the visual studio and once browser is open navigate to new button and create a  new sales order  and save  then the message will pop up  in the screen , you can debug the process also .
by loading the symbols it will take some time to load all the symbols.




Wednesday 1 May 2019

item creation and update in ax 2012

static void SON_ProductcreateAndUpdate(Args _args)
{
    #define.ProductNum()
    #define.SearchName()
    #define.StorageDim()
    #define.TrackingDim()
    #define.ItemId()
    #define.NameAlias()
    #define.ModelGroup()
    #define.ItemGroup()
    EcoResDistinctProduct               ecoResDistinctProduct;
    EcoResProductIdentifier             ecoResProductIdentifier;
    EcoResStorageDimensionGroupProduct  ecoResStorageDimensionGroupProduct;
    EcoResTrackingDimensionGroupProduct ecoResTrackingDimensionGroupProduct;
    InventTable                         inventTable;
    InventTableModule                   inventTableModule;
    MCRInventTable mcrInventTable;
    InventItemSetupSupplyType           inventItemSetupSupplyType;
    EcoResStorageDimensionGroupItem     ecoResStorageDimensionGroupItem;
    EcoResTrackingDimensionGroupItem    ecoResTrackingDimensionGroupItem;
    InventModelGroupItem                inventModelGroupItem;
    InventItemGroupItem                 inventItemGroupItem;

    EcoResProductReleaseManagerBase     releaseManager;
    SysExcelApplication                 application;
    SysExcelWorkbooks                   workbooks;
    SysExcelWorkbook                    workbook;
    SysExcelWorksheets                  worksheets;
    SysExcelWorksheet                   worksheet;
    SysExcelCells                       cells;
    COMVariantType                      type;
    FileIoPermission                    perm;
    LongDescription                     number;
    #File
    int                                 row,i;
    Name                                name;
    FileName                            filename;
    InventTableModule                   inventTableModulePurch,inventTableModuleSales,inventTableModuleInvent;
    EcoResProduct                       ecoResProduct;
    ItemId                              itemId;
    UnitOfMeasureSymbol                 purchUnit,salesUnit,inventUnit;
    InventModelGroupId                  modelGroupId;
    Name                                productType;
    EcoResProductType                   ecoResProductType;
    int                                 j;
    str                                 dimValue;
    DimensionDefault                    result;
    container                           conValue;// = _value;
    DimensionAttribute                  dimensionAttribute;
    DimensionAttributeValue             dimensionAttributeValue;
    DimensionAttributeValueSetStorage   valueSetStorage = new DimensionAttributeValueSetStorage();
    container                           conAttr = ["@SON338"];
    EcoResTrackingDimensionGroupItem    trackingDimensionGroupItem;
    EcoResTrackingDimensionGroup        trackingDimensionGroup;
    //ItemId                  itemId;
    EcoResTrackingDimensionGroupName    trDim;
    EcoResStorageDimensionGroupItem     dimensionGroupItem;
    EcoResStorageDimensionGroup         storageDimensionGroup;
    EcoResStorageDimensionGroupName     storDim;
    ItemGroupId                         itemGroup;
   // Name                                nameGroup;
    Name                                lItem,lType,shipment,pos,dD,dDWarehouse,partnerIdf,ownUse;
    NoYes                               noyes1,noyes2,noyes3,noyes4;
    SON_ShipmentType                    son_ShipmentType;
    string20                            productName;
    String10                            productKey;
    String10                             nameGroup;

    application = SysExcelApplication::construct();
    workbooks = application.workbooks();

    perm = new FileIOPermission(filename,#io_read);
    perm.assert();

    info(strFmt('%1',DateTimeUtil::getSystemDateTime()));

    //specify the file path that you want to read
    filename = @'E:\Kavin\Additional Item upload\Additionalitemupload.xlsx';
    //E:\Kavin\Additional Item upload

    try
    {
        workbooks.open(filename);
    }
    catch (Exception::Error)
    {
        throw error("File cannot be opened.");
    }
    try
    {
        //ttsBegin;
        workbook = workbooks.item(1);
        worksheets = workbook.worksheets();
        worksheet = worksheets.itemFromNum(1);
        cells = worksheet.cells();

        do
        {
            row++;
            if(row > 1)
            {
                nameGroup    = '';
                itemId       = cells.item(row, 1).value().bStr();
                productType  = cells.item(row, 2).value().bStr();
                productKey   = cells.item(row, 3).value().bStr();
                productName  = cells.item(row, 4).value().bStr();
                storDim      = cells.item(row, 5).value().bStr();
                trDim        = cells.item(row, 6).value().bStr();
                modelGroupId = cells.item(row, 7).value().bStr();
                itemGroup    = cells.item(row, 8).value().bStr();
                dD           = cells.item(row, 9).value().bStr();
                dDWarehouse  = cells.item(row, 10).value().bStr();
                inventUnit   = cells.item(row, 11).value().bStr();
                purchUnit    = cells.item(row, 12).value().bStr();
                salesUnit    = cells.item(row, 13).value().bStr();
                lItem        = cells.item(row, 14).value().bStr();
                lType        = cells.item(row, 15).value().bStr();
                shipment     = cells.item(row, 16).value().bStr();
                pos          = cells.item(row, 17).value().bStr();
                partnerIdf   = cells.item(row, 18).value().bStr();
               // ownUse       = cells.item(row, 19).value().bStr();
                nameGroup    = cells.item(row, 19).value().bStr();

                select firstOnly * from inventTable
                    where inventTable.ItemId == itemId;

                if(inventTable)
                {
                    ttsBegin;
                    select firstOnly forupdate ProductType from ecoResProduct
                        where ecoResProduct.RecId == inventTable.Product;

                    if(ecoResProduct)
                    {
                        ecoResProduct.ProductType = str2enum(ecoResProductType, productType);
                        ecoResProduct.doUpdate();
                    }
                    ttsCommit;

                    ttsBegin;
                    conValue = conNull();
                    result = 0;
                    inventTable.selectForUpdate(true);

                    if (nameGroup != '')
                    {
                        conValue = [nameGroup];

                        for (j = 1; j <= conLen(conAttr); j++)
                        {
                            dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttr,j));

                            if (dimensionAttribute.RecId == 0)
                            {
                                continue;
                            }

                            dimValue = conPeek(conValue,j);

                            if (dimValue != "")
                            {
                                dimensionAttributeValue = dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,true);
                                valueSetStorage.addItem(dimensionAttributeValue);
                            }
                        }
                        result = valueSetStorage.save();


                        if(result != 0)
                        {
                            inventTable.DefaultDimension    = result;
                        }
                    }

                    inventTable.SON_LicensedItems       = str2enum(noyes1,lItem);
                    inventTable.SON_LicenseType         = lType;
                    inventTable.RAXShipmentType         = str2enum(son_ShipmentType,shipment);
                    inventTable.SON_PosPartner          = str2enum(noyes2,pos);
                    inventTable.RAXPartnerIdentifier    = str2int(partnerIdf);
                    inventTable.RAXOwnUseItem           = str2enum(noyes3,ownUse);
                    inventTable.doUpdate();
                    ttsCommit;

                    ttsBegin;
                    select firstOnly forUpdate * from mcrInventTable
                        where mcrInventTable.InventTable == inventTable.RecId;

                    mcrInventTable.InventTable                  =  inventTable.RecId;
                    mcrInventTable.DropShipment                 =  str2enum(noyes4,dD);
                    mcrInventTable.DefaultDropShipmentWarehouse = dDWarehouse;
                    mcrInventTable.write();
                    ttsCommit;

                    ttsBegin;
                    select firstOnly * from trackingDimensionGroupItem
                        where trackingDimensionGroupItem.ItemDataAreaId == inventTable.dataAreaId
                        && trackingDimensionGroupItem.ItemId == itemId;

                    trackingDimensionGroupItem.selectForUpdate(true);

                    select firstonly RecId from trackingDimensionGroup
                        where trackingDimensionGroup.Name == trDim;

                    trackingDimensionGroupItem.ItemDataAreaId = inventTable.dataAreaId;
                    trackingDimensionGroupItem.ItemId = itemId;
                    trackingDimensionGroupItem.TrackingDimensionGroup = trackingDimensionGroup.RecId;
                    trackingDimensionGroupItem.write();
                    ttsCommit;

                    ttsBegin;
                    select firstOnly forupdate * from inventModelGroupItem
                        where inventModelGroupItem.ItemDataAreaId == inventTable.dataAreaId
                        && inventModelGroupItem.ItemId == inventTable.ItemId;

                    inventModelGroupItem.ItemDataAreaId = inventTable.dataAreaId;
                    inventModelGroupItem.ModelGroupDataAreaId = inventTable.dataAreaId;
                    inventModelGroupItem.ItemId = inventTable.ItemId;
                    inventModelGroupItem.ModelGroupId = modelGroupId;
                    inventModelGroupItem.write();
                    ttsCommit;

                    ttsBegin;
                    select firstOnly forupdate * from inventItemGroupItem
                        where inventItemGroupItem.ItemDataAreaId == inventTable.dataAreaId
                        && inventItemGroupItem.ItemId == inventTable.ItemId;

                    inventItemGroupItem.ItemGroupDataAreaId = inventTable.dataAreaId;
                    inventItemGroupItem.ItemDataAreaId = inventTable.dataAreaId;
                    inventItemGroupItem.ItemId = inventTable.ItemId;
                    inventItemGroupItem.ItemGroupId = itemGroup;
                    inventItemGroupItem.write();
                    ttsCommit;

                    ttsBegin;
                    select firstonly forUpdate UnitId from inventTableModulePurch
                        where inventTableModulePurch.ItemId == inventTable.ItemId
                        && inventTableModulePurch.ModuleType == ModuleInventPurchSales::Purch;

                    if(inventTableModulePurch)
                    {
                        inventTableModulePurch.UnitId = purchUnit;
                        inventTableModulePurch.doUpdate();
                    }
                    ttsCommit;

                    ttsBegin;
                    select firstonly forUpdate UnitId from inventTableModuleSales
                        where inventTableModuleSales.ItemId == inventTable.ItemId
                        && inventTableModuleSales.ModuleType == ModuleInventPurchSales::Sales;

                    if(inventTableModuleSales)
                    {
                        inventTableModuleSales.UnitId = salesUnit;
                        inventTableModuleSales.doUpdate();
                    }
                    ttsCommit;

                    ttsBegin;
                    select firstonly forUpdate UnitId from inventTableModuleInvent
                        where inventTableModuleInvent.ItemId == inventTable.ItemId
                        && inventTableModuleInvent.ModuleType == ModuleInventPurchSales::Invent;

                    if(inventTableModuleSales)
                    {
                        inventTableModuleInvent.UnitId = inventUnit;
                        inventTableModuleInvent.doUpdate();
                    }
                    ttsCommit;



                    ttsBegin;
                    select firstOnly * from dimensionGroupItem
                        where dimensionGroupItem.ItemDataAreaId == inventTable.dataAreaId
                        && dimensionGroupItem.ItemId == itemId;

                    dimensionGroupItem.selectForUpdate(true);

                    select firstonly RecId from storageDimensionGroup
                        where storageDimensionGroup.Name == storDim;

                    dimensionGroupItem.ItemDataAreaId = inventTable.dataAreaId;
                    dimensionGroupItem.ItemId = itemId;
                    dimensionGroupItem.StorageDimensionGroup = storageDimensionGroup.RecId;
                    dimensionGroupItem.write();
                    ttsCommit;

                    //info(strFmt("Details updated for the ItemId :: %1 ",cells.item(row, 1).value().bStr()));
                }
                else
                {
                    info(strFmt("Item not found :: %1",cells.item(row, 1).value().bStr()));
                    //create a new item
                                    //Product
                       // itemname = "Rohit6";
                       // productName = "productname";

                        ecoResDistinctProduct.clear();
                        ecoResDistinctProduct.initValue();
                        ecoResDistinctProduct.ProductType = EcoResProductType::Item;
                        ecoResDistinctProduct.DisplayProductNumber = itemId;
                        ecoResDistinctProduct.SearchName = productName;

                        if (ecoResDistinctProduct.validateWrite())
                        {
                            ecoResDistinctProduct.insert();
                            ecoResProductIdentifier.clear();
                            ecoResProductIdentifier.initValue();
                            ecoResProductIdentifier.ProductNumber = itemId;
                            ecoResProductIdentifier.Product = ecoResDistinctProduct.RecId;
                            ecoResProductIdentifier.insert();
                            //Storage dimension group
                            ecoResStorageDimensionGroupProduct.clear();
                            ecoResStorageDimensionGroupProduct.initValue();
                            ecoResStorageDimensionGroupProduct.Product = ecoResDistinctProduct.RecId;
                            ecoResStorageDimensionGroupProduct.StorageDimensionGroup = EcoResStorageDimensionGroup::findByDimensionGroupName("SiteWH").RecId;
                            if (ecoResStorageDimensionGroupProduct.validateWrite())
                            {
                                ecoResStorageDimensionGroupProduct.insert();
                            }
                            //Tracking dimension group
                            ecoResTrackingDimensionGroupProduct.clear();
                            ecoResTrackingDimensionGroupProduct.initValue();
                            ecoResTrackingDimensionGroupProduct.Product = ecoResDistinctProduct.RecId;
                            ecoResTrackingDimensionGroupProduct.TrackingDimensionGroup = EcoResTrackingDimensionGroup::findByDimensionGroupName("None").RecId;
                            if (ecoResTrackingDimensionGroupProduct.validateWrite())
                            {
                                ecoResTrackingDimensionGroupProduct.insert();
                            }
                            EcoResProductTranslation::createOrUpdateTranslation(ecoResDistinctProduct.RecId, itemId,productName);//name,descripyion
                            //Released product
                            inventTable.clear();
                            inventTable.initValue();
                            inventTable.initFromEcoResProduct(ecoResDistinctProduct);
                            inventTable.ItemId = itemId;
                            inventTable.NameAlias = productName;
                            inventTable.RAXProductKey = productKey;
                            InventTable.PmfProductType = PmfProductType::None;
                            InventTable.SON_LicensedItems       = str2enum(noyes1,lItem);
                            InventTable.SON_LicenseType         = lType;
                            InventTable.RAXShipmentType         = str2enum(son_ShipmentType,shipment);
                            InventTable.SON_PosPartner          = str2enum(noyes2,pos);
                            InventTable.RAXPartnerIdentifier    = str2int(partnerIdf);
                            InventTable.RAXOwnUseItem           = str2enum(noyes3,ownUse);
                            if (nameGroup != '')
                            {
                                conValue = [nameGroup];

                                for (j = 1; j <= conLen(conAttr); j++)
                                {
                                    dimensionAttribute = dimensionAttribute::findByName(conPeek(conAttr,j));

                                    if (dimensionAttribute.RecId == 0)
                                    {
                                        continue;
                                    }

                                dimValue = conPeek(conValue,j);

                                if (dimValue != "")
                                {
                                    dimensionAttributeValue = dimensionAttributeValue::findByDimensionAttributeAndValue(dimensionAttribute,dimValue,false,true);
                                    valueSetStorage.addItem(dimensionAttributeValue);
                                }
                                }
                                result = valueSetStorage.save();


                                if(result != 0)
                                {
                                    inventTable.DefaultDimension    = result;
                                }
                            }

                            if (inventTable.validateWrite())
                            {
                                inventTable.insert();

                                ttsBegin;
                                select firstOnly forUpdate * from mcrInventTable
                                where mcrInventTable.InventTable == inventTable.RecId;

                                mcrInventTable.InventTable                  =  inventTable.RecId;
                                mcrInventTable.DropShipment                 =  str2enum(noyes4,dD);
                                mcrInventTable.DefaultDropShipmentWarehouse = dDWarehouse;
                                mcrInventTable.write();
                                ttsCommit;

                                //Inventory model group
                                inventModelGroupItem.clear();
                                inventModelGroupItem.initValue();
                                inventModelGroupItem.ItemDataAreaId = inventTable.dataAreaId;
                                inventModelGroupItem.ItemId = inventTable.ItemId;
                                inventModelGroupItem.ModelGroupId = modelGroupId;
                                inventModelGroupItem.ModelGroupDataAreaId = curext();
                                inventModelGroupItem.insert();
                                //Item group
                                inventItemGroupItem.clear();
                                inventItemGroupItem.initValue();
                                inventItemGroupItem.ItemDataAreaId = inventTable.dataAreaId;
                                inventItemGroupItem.ItemId = inventTable.ItemId;
                                inventItemGroupItem.ItemGroupId = itemGroup;
                                inventItemGroupItem.ItemGroupDataAreaId = curext();
                                inventItemGroupItem.insert();
                                //Extended product details – Inventory
                                inventTableModule.clear();
                                inventTableModule.initValue();
                                inventTableModule.ItemId = inventTable.ItemId;
                                inventTableModule.UnitId = inventUnit;
                                inventTableModule.ModuleType = ModuleInventPurchSales::Invent;
                                inventTableModule.insert();
                                //Extended product details – Purchase
                                inventTableModule.clear();
                                inventTableModule.initValue();
                                inventTableModule.ItemId = inventTable.ItemId;
                                inventTableModule.UnitId = purchUnit;
                                inventTableModule.ModuleType = ModuleInventPurchSales::Purch;
                                inventTableModule.insert();
                                //Extended product details – Sales
                                inventTableModule.clear();
                                inventTableModule.initValue();
                                inventTableModule.ItemId = inventTable.ItemId;
                                inventTableModule.UnitId = salesUnit;
                                inventTableModule.ModuleType = ModuleInventPurchSales::Sales;
                                inventTableModule.insert();
                                //Warehouse items
                                InventItemLocation::createDefault(inventTable.ItemId);
                                //Supply type setup
                                inventItemSetupSupplyType.clear();
                                inventItemSetupSupplyType.initValue();
                                inventItemSetupSupplyType.ItemId = inventTable.ItemId;
                                inventItemSetupSupplyType.ItemDataAreaId = inventTable.DataAreaId;
                                inventItemSetupSupplyType.insert();
                                //Product storage dimension group
                                ecoResStorageDimensionGroupProduct = EcoResStorageDimensionGroupProduct::findByProduct(ecoResDistinctProduct.RecId);
                                if (ecoResStorageDimensionGroupProduct.RecId)
                                {
                                    ecoResStorageDimensionGroupItem.clear();
                                    ecoResStorageDimensionGroupItem.initValue();
                                    ecoResStorageDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;
                                    ecoResStorageDimensionGroupItem.ItemId = inventTable.ItemId;
                                    ecoResStorageDimensionGroupItem.StorageDimensionGroup   = ecoResStorageDimensionGroupProduct.StorageDimensionGroup;
                                    ecoResStorageDimensionGroupItem.insert();
                                }
                                //Product tracking dimension group
                                ecoResTrackingDimensionGroupProduct = EcoResTrackingDimensionGroupProduct::findByProduct(ecoResDistinctProduct.RecId);
                                if (ecoResTrackingDimensionGroupProduct.RecId)
                                {
                                    ecoResTrackingDimensionGroupItem.clear();
                                    ecoResTrackingDimensionGroupItem.initValue();
                                    ecoResTrackingDimensionGroupItem.ItemDataAreaId = inventTable.DataAreaId;
                                    ecoResTrackingDimensionGroupItem.ItemId = inventTable.ItemId;
                                    ecoResTrackingDimensionGroupItem.TrackingDimensionGroup = ecoResTrackingDimensionGroupProduct.TrackingDimensionGroup;
                                    ecoResTrackingDimensionGroupItem.insert();
                                }
                            }
                        }

                    //create a new item
                }//else ends here
            }
            //if (row == 2100)
            //{
                //break;
            //}
            type = cells.item(row+1, 1).value().variantType();
        }

        while (type != COMVariantType::VT_EMPTY);
        CodeAccessPermission::revertAssert();
        application.quit();
        //ttsCommit;
    }
    catch(Exception::Error)
    {
        info(strFmt('%1 - %2',DateTimeUtil::getSystemDateTime(), row));
        throw error("File upload failed");
    }

    info("File uploaded success fully");
    info(strFmt('%1',DateTimeUtil::getSystemDateTime()));
}

Monday 22 April 2019

display method in d 365 extension

1. Add a project
2.create a  new class VendPackingSlipJour_Extension for writing code in vendpackingslipjour table


[ExtensionOf(tableStr(VendPackingSlipJour))]
final public static class VendPackingSlipJour_Extension
{
    [SysClientCacheDataMethodAttribute(true)] //This attribute will cache your display method.
    public static display Name internalpcakingslipno(VendPackingSlipJour _this)
    {
        return "text";
    }

}

3. create a extesion of the form

VendPackingSlipJournal.Extension an add a string over there

datemethod as :VendPackingSlipJour_Extension::internalpcakingslipno
and datasource as VendPackingSlipJour

add a startup project as PurchTable (PurchTable.Extension1)

then run the program atlast when we navigate the product recipt of the Po we will get the new display method over there

we can also write like this

[ExtensionOf(tableStr(VendPackingSlipJour))]
final public class VendPackingSlipJour_Extension
{
    [SysClientCacheDataMethodAttribute(true)] //This attribute will cache your display method.
    public display Name internalpcakingslipno()
    {
        return "text";
    }

}

and can call the datamethod as VendPackingSlipJour_Extension.internalpcakingslipno

here please make sure we add
[ExtensionOf(tableStr(VendPackingSlipJour))]

and _Extension please pay extra attention to the spelling of the "extension" if it goes wrong the display method wont work.


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;
}

intercompany PO multiple product receipt by x++

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