Translate

Sunday, July 26, 2020

BOM Activate Based on BOM ID AX2012 R3

static void BOMActive(Args _args)

{

    Dialog                  dialog  = new Dialog();

    LedgerJournalName       _LedgerJournalName;

    str                     _BusinessUnit,_Account ;

    NumberSeq               _numberSeq;

    int num;

    BOMTable                _BOMTable,_BOMTable1, _BOMTable2;

    BOM                     _BOM,_BOM1,_BOM2;

    EcoResProductMaster     _EcoResProductMaster;

    EcoResProductMasterColor _EcoResProductMasterColor;

    EcoResColor             _EcoResColor;

    BOMVersion              _BOMVersion,_BOMVersion1,_BOMVersion2;

    InventDim               inventDim, _inventDim1, inventDimNew,_InventDim,_invtdim;

    ReqItemTable            _ReqItemTable, _ReqItemTable1, _ReqItemTable_check;

    InventTableModule       _InventTableModule;

    InventTable             _inventTable;

    InventSum               _inventSum;

    InventPosting           _inventposting;

  

    str dimid;

 

 

    DialogField dialogField,typeofJournal;

    RecId    a ;

    container offsetDimensions;

    Voucher _Voucher;

    CustLedgerAccounts                _custLegerAccount, _custLegerAccount1;

    DimensionAttributeValueCombination _DimensionAttributeValueCombination,_DimensionAttributeValueCombination1;

    RecId   _RecId;

    AsciiIo importFile,logFile;

    str filePath,fileNameOnly;

    LedgerJournalTable      _LedgerJournalTable;

    LedgerJournalTrans      _LedgerJournalTrans;

    Currency                _Currency;

    LedgerVoucher           _LedgerVoucher;

    int rowcount;

    NumberSequence          _NumberSequence;

    //filetype type;

    container record;

     SysExcelApplication  xlsApplication;

     SysExcelApplication application;

     SysExcelWorkbooks workbooks;

     InventTrans        _InventTrans;

    InventTransOrigin   _InventTransOrigin;

     SysExcelWorkbook workbook;

     SysExcelWorksheets worksheets;

     SysExcelWorksheet worksheet;

     SysExcelWorkBooks    xlsWorkBookCollection;

     SysExcelWorkBook     xlsWorkBook;

     SysExcelWorkSheets   xlsWorkSheetCollection;

     SysExcelWorkSheet    xlsWorkSheet;

     SysExcelRange        xlsRange;

     NumberSequenceTable  _NumberSequenceTable;

     SysOperationProgress progress = new SysOperationProgress() ;

    LedgerJournalTransTaxExtensionIN  _LedgerJournalTransTaxExtensionIN;

     SysExcelCells cells;

    str  Item;

     COMVariantType type;

    int totalRecords, totalInserted,totalFail,x,srNum,row;

    str NewFileName,FileName,billNo,Segment,NewJournalNum,NewJournalNum1, change;

    int journalnum ;

    real LRNo;

    str 20 approver1   = '1154';//Approver User ID

    BOMApprove bomApprove = new BOMApprove();

    RecId approver = HcmWorker::findByPersonnelNumber(approver1).RecId;

    BOMId bomid

    ;

    dialogField=dialog.addField(extendedTypeStr(FilenameOpen),"Select File","Select file to import");

 

    dialog.caption("Select File To Import");

    row=2;

    application = SysExcelApplication::construct();

    workbooks = application.workbooks();

    if(!dialog.run())

    return;

    [filePath, fileNameOnly, type] = fileNameSplit(dialogField.value());

    FileName=dialogField.value();

    NewFileName=strReplace(FileName,@"\",@"\\");

    try

        {

            workbooks.open(NewFileName);

        }

        catch (Exception::Error)

        {

            throw error("File cannot be opened.");

        }

    workbook = workbooks.item(1);

    worksheets = workbook.worksheets();

    worksheet = worksheets.itemFromNum(1);

    cells = worksheet.cells();

    x=2;

    srNum=1;

 

 

 

     while(cells.item(row,1).value().bStr()!="")

    {

        //_BOMTable = BOMTable::find(cells.item(row,1).value().bStr());

 

        bomid                    = cells.item(row,1).value().bStr();

        select forUpdate _BOMVersion where _BOMVersion.BOMId==bomid;

 

        _BOMVersion.Approved = true;

         _BOMVersion.Active = true;

         _BOMVersion.Approver = approver;

         ttsBegin;

     _BOMVersion.write();

     ttsCommit;

     bomApprove.init();

     bomApprove.parmApprover(approver);

     bomApprove.parmBOMId(bomid);

     bomApprove.run();

 

 

     row++;

 

     }

         info(strFmt("Upload Successfully"));

 

}

 

  

Sunday, February 9, 2020

About FormRef Table Property in Ax 2012

What is the use of Form Ref:

Specifies the display menu item that is activated when a table is referenced. A display menu item is associated with a form.

When you use a primary index field on a report, this form is available as a link in the report. A primary index is specified by using the PrimaryIndex property.

If you leave this field blank, the system attempts to display a form that has the same name as the table.

Today I'm gonna to explore About Table Property of “FormRef”

Create a New Table as Below Screen shot



Create One Related Table For Above Table  as below Screen Shot:


Open Table SKP_FormRefEx_B insert values as below screen shot



Now, right click on the ID value, select View Details as below screen shot


A warning message appears as below screen shot: it occurs by the Related field of SkP_FormRefEX_A
i.e SkP_FormRefEX_A table Is not having any FormRef Property value


Now I use to Keep Form Reference for SkP_FormRefEX_A table
First I need to create one Form As below Screenshot

>> Create Menu One Display MenuItem for above Form

Now Goto SkP_FormRefEX_A table & Keep Above Menuitem as FormRef


 Goto SkP_FormRefEX_B table, open it Right click on related field of SkP_FormRefEX_A table  and  Select View Details as Above process


Finally,FormRef Property is achieved as above screenshot explains clear view of it.

Sunday, January 12, 2020

Get Batch Reserve Quantity with Item Id Unit Conversion

The code below returns the batch-reserved quantity with unit conversion based on the item's unit setup. If unit conversion is not required, use the method without conversion logic.

/// <summary>

/// Get reserve physical Quantity
/// </summary>
/// <param name = "_salesLine">Sales line</param>
/// <returns>Reserve physical Qty</returns>
public InventQtyReservPhysical getReservedPhysicalQty(SalesLine  _salesLine)
{
    InventQtyReservPhysical inventQtyReservPhysical;
    if(_salesLine!=null)
    {
        InventTable inventTable = InventTable::find(_salesLine.ItemId);
        inventQtyReservPhysical = decRound(UnitOfMeasureConverter::convert(_salesLine.reservedPhysical(),
        UnitOfMeasure::unitOfMeasureIdBySymbol(inventTable.inventUnitId()),
        UnitOfMeasure::unitOfMeasureIdBySymbol(_salesLine.SalesUnit),
        NoYes::No,
        InventTable::itemProduct(inventTable.ItemId),
        NoYes::No), 
        0);
    }
    return inventQtyReservPhysical;
}

Upload file in azure storage account in Dynamics 365 FnO

In this blog, I will discuss how we can upload a file to a storage account in D365FO. We normally use an Azure storage account to hold things that need to be further processed and stored in the cloud.

Please see the code below with an explanation.

Explanation of source code :
  • Getting Azure credentials from vendor parameter tables.
  • Setting the connection to access the storage account.
  • Initialise the cloud file client, which is used to configure and execute requests against the File service
  • Initialise cloud file share.
  • Check file share exists or not.
  • Initialise cloud file directory, which is a directory of files that hold directories, and directories hold files.
  • Gets a reference to a virtual blob directory beneath this container.
  • Initialise the cloud file.
  • Uploads a stream to a file. If the file already exists on the service, it will be overwritten.
Source Code (Method):

/// <summary>
    /// Upload file to Azure file storage
    /// </summary>
    /// <param name = "_fileContentInStream">File stream</param>
    /// <parmam name = "_folderName">Folder where file saves</param>
    /// <param name = "_fileName">File name</param>
    /// <returns>True or False</returns>
    public static boolean uploadFileToAzureFileStorage(System.IO.Stream _fileContentInStream , str _folderName, str _fileName)
    {
        try
        {
            //Getting Azure credentials from vendor parameter tables (in my case)
            VendParameters  vendParameter = VendParameters::find();

            //Setting connection
            Microsoft.WindowsAzure.Storage.Auth.StorageCredentials storageCredentials  new Microsoft.WindowsAzure.Storage.Auth.StorageCredentials("storage account name""storage account access key"); 
            Microsoft.WindowsAzure.Storage.CloudStorageAccount storageAccount  new Microsoft.WindowsAzure.Storage.CloudStorageAccount(storageCredentials, true);
           
            //Provides a client-side logical representation of the Microsoft Azure File service.
            //This client is used to configure and execute requests against the File service.
            Microsoft.WindowsAzure.Storage.File.CloudFileClient fileClient = storageAccount.CreateCloudFileClient();
           
            //Represents a share in the Microsoft Azure File service.
            Microsoft.WindowsAzure.Storage.File.CloudFileShare share = fileClient.GetShareReference("Your file share name");

            //If not exist, throw an error
            if (!share.Exists(nullnull))
            {
                throw error(strFmt("File share not exists."));
            }

            //Represents a directory of files which hold directories, and directories hold files.
            Microsoft.WindowsAzure.Storage.File.CloudFileDirectory cloudDir = share.GetRootDirectoryReference();

            container conFolders = str2con(_folderName, '/');

            for (int i = 1; i <= conlen(conFolders); i++)
            {
                str folderName = conpeek(conFolders, i);

                //Gets a reference to a virtual blob directory beneath this container.
                cloudDir = cloudDir.GetDirectoryReference(folderName);
                cloudDir.CreateIfNotExists(nullnull);
            }

            //Represents a file in the Microsoft Azure File service.
            Microsoft.WindowsAzure.Storage.File.CloudFile file = cloudDir.GetFileReference(_fileName);

            //Have to run Seek on Stream.
            if (_fileContentInStream.CanSeek)
            {
                _fileContentInStream.Seek(0, System.IO.SeekOrigin::Begin);
            }

            //Uploads a stream to a file. If the file already exists on the service, it will be overwritten
            file.UploadFromStream(_fileContentInStream, nullnullnull);

            return true;
        }
        catch
        {
            return false;
        }
    }