Search This Blog

Thursday 25 September 2014

Getting the DataSource of the Caller Form

I was working on scenario in which there another form is open from one form and I need to get the datasource from the caller form in my new form.

The code to get the datasource of the caller form is:

CustTable = custTable;

if(element.args().record().TableId == tablenum(CustTable))
{
    custTable = element.args().record();
}


Thanks

Muhammad Zahid.


Friday 29 August 2014

Convert Currency based on the Exchange Rates in Microsoft Dynamics AX 2012

In Microsoft Dynamics there is a method available for converting the amount from one currency to another based on the exchange rates.

The method that I am talking about is curPrice2CurPrice method in Currency table.

Below is the code of this method








You have to pass the price and the old currency in which the price actually is and the new currency in which you are converting the price.

Same method is implemented on Purchase Order Form.You can see the existing behavior if you have R2 installed.Just create new purchase order and than create some purchase order lines in it and than in the purchase order header tab change the currency.

After changing the currency the unit price in the purchase order line will convert based on the currency that you have selected.

You can see the below images before and after changing the currency on purchase order.

 Before changing the currency:

  
After changing the currency:

You can also see the exchange rates on the below navigation path:

GL --> Setup --> Exchange rate type --> Set Default --> check currency for which you need to check the exchange rate for

This was related to the currency and exchange rates.
I hope you like it :)

Thanks

Muhammad Zahid.

Wednesday 23 July 2014

Export to Excel: The number of arguments provided is different from the number of arguments accepted by the method.

I was working on excel based reports was getting the following error:

"The number of arguments provided is different from the number of arguments accepted by the method."

After debugging I found out that when I going to insert the text in excel this error was generating.

the code that was reproducing this error is:

cell.value("my text");

The best solution to get rid of this error is that we should open our workbook for very less amount of time.We should first complete all of our calculations and than open the workbook and  insert the records in excel sheet. 

If the issue is not resolve by applying the above workaround than there are also some other solutions available you can see on the below link:  



I hope you like this post.

Thanks

Muhammad Zahid.





Wednesday 25 June 2014

Export to Excel change cell format to percentage format in Microsoft Dynamics AX 2012

Below is the code snippet to change the cell format to percentage format.

cells.range("D21:D30").numberFormat("0.00%");

Below is the link for more info on excel cells format.

http://www.teachexcel.com/free-excel-macros/m-72,Format-Cells-as-a-Percentage-in-Excel-Number-Formatting.html


Thanks

Muhammad Zahid.

Export to Excel in Microsoft Dynamics AX 2012

Below is the sample code snippet to export the data from Microsoft Dynamics AX to Excel.

Example no 1:

            SysExcelWorkbooks workbooks;
            SysExcelWorkbook workbook;
            SysExcelWorksheets worksheets;
            SysExcelWorksheet worksheet;
            SysExcelCells cells;
            SysExcelCell cell;
   
            application = SysExcelApplication::construct();
            workbooks = application.workbooks();
            workbook = workbooks.add();
            worksheets = workbook.worksheets();
            worksheet = worksheets.itemFromNum(1);
            cells = worksheet.cells();
           
            cell = cells.item(row, col);
       
            cell.value("sample Code");
           
            worksheet.columns().autoFit(); //use to autofit the columns of the excel sheet
       
            application.visible(true);

IF you want to print some Headings in Bold format and in more than one cell:

Example No 2:

             fontSizeRange   = #B+int2str(2)+","+#C+int2str(2);
             mergeCellsRange = #B+int2str(2)+":"+#C+int2str(2);
       
             this.insertValue(row,col,"Project Comparison Budget VS               Actual",true,fontSizeRange,13,true,mergeCellsRange,false,0);
           
             public void insertValue(int         _row,
                                int         _col,
                                anytype     _value,
                               boolean     _isFontBold = false,
                                str         _fontSizeRange = "",
                                int         _fontSizeWeight = 11,
                                boolean     _isMergeCell = false,
                                str         _mergeRange = "",
                                boolean     _allignment  = false,
                                int         _allignmentType = #xlLeft)
            {
       
                cell = this.parmCells().item(_row, _col);
                cell.value(_value);
       
                if (_isFontBold)
                {
                    font = cell.font();
                    font.bold(_isFontBold);
                }
                if (_fontSizeRange != "")
                {
                    worksheetCOM    = this.parmWorksheet().comObject();
                    rangeCOM        = worksheetCOM.Range(_fontSizeRange);
                    fontCOM         = rangeCOM.Font();
                    fontCOM.Size(_fontSizeWeight);
                }
                if (_isMergeCell)
                {
                    range = this.parmCells().range(_mergeRange);
                    range.comObject().MergeCells(1);
                }
                if (_allignment)
                {
                    if (_isMergeCell)
                    {
                        range.horizontalAlignment(_allignmentType);
                    }
                    else
                    {
                        cellCOM =  cell.comObject();
                        range = this.parmCells().range(cellCOM.address()+":"+cellCOM.address());
                        range.horizontalAlignment(_allignmentType);
                    }
                }
            }

This was all related to the export to excel.

If you have any query related to export to excel than feel free to comment.


Thanks

Muhammad Zahid



SSRS Reports Range Bar Chart Show Start and End Date Only

Below are the steps to show the start and end date only in a range bar chart in SSRS reports.

First of all just select the Horizontal Axis of the chart as you can see this in the below image.










Now right click this horizontal axis and than select axis properties.

A new window will open select the first tab i.e Axis Options.As you can see this window in the below image.


As you can see in the above image in the minimum text box select the startdate and in the maximum text box select the end date and in the interval write the expression i.e

=datediff("d", Fields!PSASchedStart.Value, Fields!PSASchedEnd.Value)

after that click ok and than save the report.

After running the report you will see that you can only see the start and end dates in the range bar chart as you can see in the below image.









This was all related to the range bar chart showing the start and end date only.

Below is the link for more information

http://stackoverflow.com/questions/18004792/ssrs-chart-x-axis-show-start-and-end-date-only

If you have any issues feel free to comment on this.

Thanks

Muhammad Zahid.

SSRS Reports Hide Duplicate Records and White Spaces

Some times while working on SSRS reports there are some duplicate records issue occurs.

Like you can see this in the below image.











Now to remove the duplicate records just right click the table and than select properties and than set the hidden property to:

=Fields!ActivityNumber.Value = Previous(Fields!ActivityNumber.value)

AS you can see the property in the below image:








Now after setting this property the data on the report looks like this:








In the above image the duplicate  record is hidden but the issue is that there are some white spaces left between the rows.

Two resolve this issue we have to remove the expression from the hidden property of the table.
And than  select the row and than right click select row group and than select the group properties as you can see this in the below image














After selecting the group properties now select  select visibility and than add the expression that we have added above in the hidden property i.e

=Fields!ActivityNumber.Value = Previous(Fields!ActivityNumber.value)

As you can see this in the below image.



  



Now after doing that the duplicate records will be remove and also the white spaces between the rows will be remove as you can see that in the below image.







The above example that I have given is related to hiding row based on single column.If you want to hide the records based on two or more columns that you can use the below expression.

=(Fields!Voucher.Value = Previous(Fields!Voucher.Value)) And (Fields!AccountNum.Value = Previous(Fields!AccountNum.Value))

The above expression means that if the voucher and the AccountNum both are repeating than report short hide the row.

This was all related to the duplicate records and white spaces.
Below are some more links related to this.

http://glutenfreesql.wordpress.com/2012/10/02/ssrs-hide-duplicates/

http://stackoverflow.com/questions/11562043/trying-to-get-rid-of-white-space-in-ssrs-report

http://dba.stackexchange.com/questions/53727/how-to-hide-rows-in-ssrs-report


If you have any questions related to that than feel free to comment on this.


Thanks

Muhammad Zahid.