Monday, November 26, 2018

Remove reservations and markings from a sales orders in Ax 2012/ D365 F&O x++



Below is the code where we can unreserve the inventory from sales orders/sales order lines.

Paste the below in a JOB

Static void Tutorial_UnreserveSalesTable(Args _args) { InventTrans inventTrans; InventTransOrigin inventTransOrigin; SalesLine salesLine; InventMovement inventMovement; InventUpd_Reservation inventUpd_Reservation ; SalesId SalesId = "001260";//<--- Send/get sales id here // Remove reservations and markings on a reserved salesorder while select inventTrans where inventTrans.StatusReceipt == StatusReceipt::None && (inventTrans.StatusIssue == StatusIssue::ReservPhysical || inventTrans.StatusIssue == StatusIssue::ReservOrdered) exists join inventTransOrigin where inventTransOrigin.RecId == inventTrans.InventTransOrigin exists join salesLine where salesLine.InventTransId == inventTransOrigin.InventTransId && SalesLine.SalesId == SalesId { if (inventTrans.MarkingRefInventTransOrigin) { InventTransOrigin::deleteMarking(inventTrans.MarkingRefInventTransOrigin, inventTrans.InventTransOrigin, -inventTrans.Qty, true); InventTransOrigin::deleteMarking(inventTrans.InventTransOrigin, inventTrans.MarkingRefInventTransOrigin, inventTrans.Qty, true); } if (inventTrans.StatusIssue == StatusIssue::ReservPhysical || inventTrans.StatusIssue == StatusIssue::ReservOrdered) { Inventmovement = inventTrans.inventmovement(true); inventUpd_Reservation = InventUpd_Reservation::newInventDim(inventmovement,inventTrans.inventDim(), -1 * inventTrans.Qty, false); inventUpd_Reservation.updatenow(); } } }


@Rahul

Monday, November 12, 2018

How to get sales order totals in D365 F&O/ AX 7 x++

Below is the the piece code we can use for getting the sales order totals.

class SW_CST_Tableid2name
{       
    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {   
        SalesTotals salesTotals;
        SalesTable salesTable;
        SalesLine salesLine;

        TaxAmountCur salesAmt,taxAmount,amt1,discountAmt,totcharges,totOfOrder,contributionRatio;
        Tax tax;

        ;
        salesTable = SalesTable::find("SO00094903");
        salesLine = SalesLine::find(salesTable.SalesId);
        salesTotals = SalesTotals::construct(salesTable, SalesUpdate::All);
        tax = Tax::construct(NoYes::No);

        salesAmt    = salesTotals.totalBalance();
        taxAmount   = salesTotals.totalTaxAmount();
        discountAmt = salesTotals.totalEndDisc();
        totcharges  = salesTotals.totalMarkup();
        totOfOrder  = salesTotals.totalAmount();
        //contributionRatio   = salesTotals.totalContributionRatio();

        info(Strfmt("Subtotal Amount %1",salesAmt ));
        info(Strfmt("The tax amount is %1",taxAmount ));
        info(Strfmt("The Discount is %1",discountAmt ));
        info(Strfmt("Charges/ Markup %1",totcharges ));
        info(Strfmt("Invoice Amount %1",totOfOrder ));
        info(Strfmt("Contribution ratio %1",contributionRatio ));
    }

}

Friday, November 2, 2018

The working folder C:\Users\Adminab12363\Documents\Visual Studio 2015\Projects is already in use by the workspace dev669312-1;oldaccount@xyz.com on computer dev669312-1.

Hi Guys,

I got the below error while I was trying to create a new workspace  for my new account.

The working folder C:\Users\Adminab12363\Documents\Visual Studio 2015\Projects is already in use by the workspace dev669312-1;oldaccount@xyz.com on computer dev669312-1.


Reason: Multiple workspaces bounded.  

Solution: In my case I deleted my old account workspace by using command prompt.

-> Go to  C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE
open command prompt as an admin.




Follow the syntax
tf workspace /delete "WORKSPACENAME;PREVIOUSUSERACCOUNT”


copy and paste in the command prompt and hit enter, then select "Y".

tf workspace /delete "SBIN001-3;rahulax@xyz.com"

Delete workspace of another user in Visual studio 2015 TFS

Hi Guys,

Here I'm showing yow how to delete a workspace of a user in Visual studio.

-> Go to  C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE
open command prompt as an admin.




Follow the syntax
tf workspace /delete "WORKSPACENAME;PREVIOUSUSERACCOUNT”


copy and paste in the command prompt and hit enter, then select "Y".

tf workspace /delete "SBIN001-3;rahulax@xyz.com"


That's it.

Monday, October 29, 2018

display/show the inventory dimensions as parameters on SSRS reports in Dynamics 365 F&O / AX 7

All the inventory dimensions are available to be selected on report parameters below. You will see this view in almost all inventory reports and other module reports.
image
Well, Let me explain how to achieve this and retrieve the values in the data provider class
Its very simple, we need to make use of the contract class for this inventory dimensions view.
Standard has got a InventDimViewContract class with all the parm inventory dimensions methods and we can use these methods later in the DP classes for the selected inventory dimensions by the user on the report parameters screen.
Create an Object for InventDimViewContract in your contract class as shown below [Please note: I am using ProdPickListContract] as an example below
image
Then add a new parm method to the contract as shown below.
[DataMemberAttribute(‘InventDimViewContract’)]
public InventDimViewContract parmInventDimViewContract(InventDimViewContract _inventDimViewContract = inventDimViewContract)
{    
    inventDimViewContract = _inventDimViewContract;
    return inventDimViewContract;
}
That’s it, by adding the above discussed,we will get the inventory dimensions on the parameters screen.
Now, the question is how do we get the selected dimensions from the user. Its simple again.
In your data provider class, mainly in processReport method, get the object of the contract class and call the parmInventDimViewContract() method, this object will help you to retrieve the inventory dimensions selected by the user by using parm methods in it. [Example : ParmViewConfigId(), parmViewInventBatchId() etc]. Please refer to screen shot below.
image
You can use these selected inventory dimensions values based on your requirements. The above screen shot is just an example of retrieving the values.

How to read data from Excel using X++ Code in D365 F&O / AX 7

Below is the code snippet which will be handy to read the data from excel using code in D365/ax 7
Please note that, in D365 SysExcel* classes have been deprecated.
Under your references node in solution explorer, add Microsoft.Office.InterOp.Excel reference
Use OfficeOpenXML namespace to achieve this. Improvise the below snippet based on your need.
using System.IO;
using OfficeOpenXml;
using OfficeOpenXml.ExcelPackage;
using OfficeOpenXml.ExcelRange;

class SRReadFromExcel_D365
{       
    public static void main(Args _args)
    { 
        System.IO.Stream            stream;
        ExcelSpreadsheetName        sheeet;
        FileUploadBuild             fileUpload;
        DialogGroup                 dlgUploadGroup;
        FileUploadBuild             fileUploadBuild;
        FormBuildControl            formBuildControl;
        Dialog                      dialog = new Dialog(“Import the data from Excel”);

        dlgUploadGroup          = dialog.addGroup(“@SYS54759”);
        formBuildControl        = dialog.formBuildDesign().control(dlgUploadGroup.name());
        fileUploadBuild         = formBuildControl.addControlEx(classstr(FileUpload), ‘Upload’);
        fileUploadBuild.style(FileUploadStyle::MinimalWithFilename);
        fileUploadBuild.fileTypesAccepted(‘.xlsx’);

        if (dialog.run() && dialog.closedOk())
        {
            FileUpload fileUploadControl     = dialog.formRun().control(dialog.formRun().controlId(‘Upload’));
            FileUploadTemporaryStorageResult fileUploadResult = fileUploadControl.getFileUploadResult();

            if (fileUploadResult != null && fileUploadResult.getUploadStatus())
            {
                stream = fileUploadResult.openResult();
                using (ExcelPackage Package = new ExcelPackage(stream))
                {
                    int                         rowCount, i;
                    Package.Load(stream);
                    ExcelWorksheet  worksheet   = package.get_Workbook().get_Worksheets().get_Item(1);
                    OfficeOpenXml.ExcelRange    range       = worksheet.Cells;
                    rowCount                  = worksheet.Dimension.End.Row – worksheet.Dimension.Start.Row + 1;

                    for (i = 2; i<= rowCount; i++)
                    {
                        info(range.get_Item(i, 1).value);
                        info(range.get_Item(i, 2).value);
                    }
                }
            }
            else
            {
                error(“Error here”);
            }

        }
    }

}

Export data into Excel using X++ code in D365 F&O / AX 7

Below is the quick code snippet to export the data to excel/create an excel in AX 7/D365 for operations
Please note, in D365 we can achieve this through OfficeOpenXml namespace
Improvise it based on your requirement
using System.IO;
using OfficeOpenXml;
using OfficeOpenXml.Style;
using OfficeOpenXml.Table;
class SRWriteToExcel
{
    public static void main(Args _args)
    {
        CustTable custTable;
        MemoryStream memoryStream = new MemoryStream();

        using (var package = new ExcelPackage(memoryStream))
        {
            var currentRow = 1;

            var worksheets = package.get_Workbook().get_Worksheets();
            var CustTableWorksheet = worksheets.Add("Export");
            var cells = CustTableWorksheet.get_Cells();
            OfficeOpenXml.ExcelRange cell = cells.get_Item(currentRow, 1);
            System.String value = "Account Number";
            cell.set_Value(value);
            cell = null;
            value = "Currency";
            cell = cells.get_Item(currentRow, 2);
            cell.set_Value(value);

            while select CustTable
            {
                currentRow ++;
                cell = null;

                cell = cells.get_Item(currentRow, 1);
                cell.set_Value(CustTable.AccountNum);
                cell = null;

                cell = cells.get_Item(currentRow, 2);
                cell.set_Value(CustTable.Currency);
            }
            package.Save();
            file::SendFileToUser(memoryStream, ‘Test’);
           
        }
       
    }

}

What is the primary purpose of using a Solution in Microsoft Power Platform & ALM?

As organizations embrace low-code development with Microsoft Power Platform , it becomes essential to manage and govern apps, flows, and dat...