Friday, December 11, 2015

Cross-Company-External record context

I faced a situation where I had to convert a listpage to cross company in EP. So I changed the query and redeployed. Pretty easy stuff. But then on clicking the record it opens a web control for approval and same thing happens with a button in the toolbar above. So in the case of cross company the web control was getting displayed blank as it wasn't getting the record context.

So I was able to handle the toolbar button by changing it's property "External Record Context" but couldn't handle the record link (HyperLinkButton). I tried getting the record context using IAxaptaAdapter but it didn't seem to work. :(


Wednesday, December 2, 2015

Cheque Report in Ax2012

Classes related to the Cheque report:
http://dynamicsuser.net/forums/p/59551/319006.aspx

https://stoneridgesoftware.com/dynamics-ax-development-check-basics/

Tuesday, December 1, 2015

Manually generate Number Sequence & release unused

The below code is to manually generate the number from the Number Sequence code:

numberSeq = NumberSeq::newGetNumFromCode(BankAccountTable::findByLedgerDimension(this.OffsetLedgerDimension).FundsTransferRefNum);

Sometimes we face this situation where number sequence doesn't release the unused numbers even if the Number sequence is configured as "Continuous". In that case we can use the below code:

NumberSeq::releaseNumber(NumberSequenceTable::findByNaturalKey(BankAccountTable::findByLedgerDimension(this.OffsetLedgerDimension).FundsTransferRefNum).RecId, ledgerJournalTrans_FundsTransfer.FundsTransferRefNum);

Conditionally hide Report Viewer buttons Ax2012

Today I was stuck in a situation where I had to disable the export button on the report viewer if the journal is not posted. After googling I got the below code which sits on the SRSReportViewer form:

private void hideExportButton()
{
    System.Windows.Controls.UIElementCollection elementLocal;
    Microsoft.Reporting.WinForms.ReportViewer   reportViewer;

    elementLocal = _AxReportViewer_Control.get_Children();
    reportViewer = elementLocal.get_Item(0);
    reportViewer.set_ShowExportButton(false);
}
Credit: http://www.agermark.com/2014/12/hide-export-button-from-report-viewer.html

You should have either different designs or menuItems for each condition to be called on the "init" method of the "SRSReportViewer" form. Add your custom code to call the hideExportButton where "_AxReportViewer_Control" is initialized.

// In case of multiple designs
    if(this.controller().parmReportName() like "*FundsTransferNoExport*")
    {
        this.hideExportButton();
    }
// In case of multiple menuitems
    if(this.args().menuItemName("*FundsTransfer*"))
    {
        this.hideExportButton();
    }

Monday, November 23, 2015

The formatter threw an exception while trying to deserialize the message Ax2012

Today I received below error first while deploying report then while viewing it:
The formatter threw an exception while trying to deserialize the message: There was an error while trying to deserialize parameter http://tempuri.org/:queryBuilderArgs. The InnerException message was 'Element 'http://tempuri.org/:queryBuilderArgs' contains data from a type that maps to the name 'http://schemas.datacontract.org/2004/07/XppClasses:SrsReportProviderQueryBuilderArgs'. The deserializer has no knowledge of any type that maps to this name. Consider using a DataContractResolver or add the type corresponding to 'SrsReportProviderQueryBuilderArgs' to the list of known types - for example, by using the KnownTypeAttribute attribute or by adding it to the list of known types passed to DataContractSerializer.'.  Please see InnerException for more details.

The solution to this was:
1. Delete all records from SysClientSessions.
2. Restart AOS.
3. Restart SSRS.
4. If above steps don't work then you can also try deleting the existing report and redeploying. Or deleting AUC files. And also deleting the XPPIL folder and performing full CIL.

Or the best way when you face this error in production environment and cannot take a downtime:
Just deactivate and re-activate the BIServices Inbound Port and the magic is done.

Source:
https://community.dynamics.com/ax/f/33/t/112982

Tuesday, October 20, 2015

Get list of object AX2012

This is the jobto save it in excel:

static void Job40(Args _args)
{
    UtilElements    UtilElementsLocal;
    SysExcelApplication application;
    SysExcelWorkbooks workbooks;
    SysExcelWorkbook workbook;
    SysExcelWorksheets worksheets;
    SysExcelWorksheet worksheet;
    SysExcelCells cells;
    SysExcelCell cell;
    int row;
    ;

    application = SysExcelApplication::construct();
    workbooks = application.workbooks();
    workbook = workbooks.add();
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1);
    cells = worksheet.cells();
    cells.range('A:A').numberFormat('@');

    cell = cells.item(1,1);
    cell.value("Object");
    row = 1;
    while select * from UtilElementsLocal
        where UtilElementsLocal.recordType == UtilElementType::WebControl
        && UtilElementsLocal.utilLevel == UtilEntryLevel::usr//global::currentAOLayer()
    {
        row++;
        cell = cells.item(row, 1);
        cell.value(UtilElementsLocal.name);
    }

    application.visible(true);
}

You can change the type of object you want and also from which layer you want in UtilElementType & UtilEntryLevel respectively.

Another way is to use Shell command:
Type C:\>(Get-AXModel -Model “USR Model” -Details).Elements | Out- File <File path>

Monday, September 21, 2015

Publish-AxReport parameters

Publish-AXReport

Deploys reports from Microsoft Dynamics AX to a Microsoft SQL Server Reporting Services instance.

Syntax

Parameter Set: Default
Publish-AXReport -Id <String> [-ModifiedAfter <DateTime> ] [-ReportName <String> ] [-RestartReportServer] [-ServicesAOSName <String> ] [-ServicesAOSWSDLPort <Int32> ] [-ServicesFilePath <String> ] [-SkipDeletingExistingReport] [-SkipReportServerAdminCheck] [ <CommonParameters>]

Detailed description

The Publish-AXReport cmdlet deploys reports from Microsoft Dynamics AX to a Reporting Services instance. By default, previously deployed report metadata is deleted and replaced when reports are deployed.

Parameters

-Id<String>

Specifies the identifier of the configuration to use to connect Microsoft Dynamics AX and Reporting Services.

Aliases
none
Required?
true
Position?
named
Default Value
none
Accept Pipeline Input?
false
Accept Wildcard Characters?
false

-ModifiedAfter<DateTime>

Limits the reports to be deployed to those modified after a specified date. Use the date format specified by your operating system. If you do not know the format, you can run the Get-AXReport cmdlet to see the format of ChangedDate.

Aliases
none
Required?
false
Position?
named
Default Value
none
Accept Pipeline Input?
false
Accept Wildcard Characters?
false

-ReportName<String>

Specifies the names of the reports to be deployed.

Aliases
none
Required?
false
Position?
named
Default Value
none
Accept Pipeline Input?
false
Accept Wildcard Characters?
false

-RestartReportServer

Forces the Reporting Services service to restart after a report is deployed.

Aliases
none
Required?
false
Position?
named
Default Value
none
Accept Pipeline Input?
false
Accept Wildcard Characters?
false

-ServicesAOSName<String>

Specifies the name of a Microsoft Dynamics AX Application Object Server (AOS) instance to connect to instead of the default value.

Aliases
none
Required?
false
Position?
named
Default Value
none
Accept Pipeline Input?
false
Accept Wildcard Characters?
false

-ServicesAOSWSDLPort<Int32>

Specifies the web service (WSDL) port of an AOS instance to connect to instead of the default value.

Aliases
none
Required?
false
Position?
named
Default Value
none
Accept Pipeline Input?
false
Accept Wildcard Characters?
false

-ServicesFilePath<String>

Specifies a client configuration parameter file (.axc) to use instead of the configuration that is stored in the registry.

Aliases
none
Required?
false
Position?
named
Default Value
none
Accept Pipeline Input?
false
Accept Wildcard Characters?
false

-SkipDeletingExistingReport

Specifies that the cmdlet should not delete existing report design metadata when executed.

Aliases
none
Required?
false
Position?
named
Default Value
none
Accept Pipeline Input?
false
Accept Wildcard Characters?
false

-SkipReportServerAdminCheck

Specifies that the cmdlet should be executed without checking whether the user has administrator rights on Reporting Services.

Aliases
none
Required?
false
Position?
named
Default Value
none
Accept Pipeline Input?
false
Accept Wildcard Characters?
false

<CommonParameters>

This cmdlet supports the common parameters: Verbose, Debug, ErrorAction, ErrorVariable, OutBuffer, OutVariable, WarningAction, and WarningVariable. For more information, see about_CommonParameters http://go.microsoft.com/fwlink/?LinkID=113216

Inputs

The input type is the type of the objects that you can pipe to the cmdlet.
  • None

    You cannot pipe input to this cmdlet.

Outputs

The output type is the type of the objects that the cmdlet emits.
  • None

    The cmdlet does not generate any output.

Examples

This example publishes reports whose names start with CustomReports and that were modified after October 10, 2011 to the report server configuration ReportServer01, and then forces the server to restart.

C:\PS>Publish-AXReport -Id ReportServer01 -ModifiedAfter 2011-10-10 -ReportName CustomReports* -RestartReportServer

Source: https://msdn.microsoft.com/en-us/library/jj720262.aspx



Deploy report to a specific AOS instance

Publish-AXReport –ReportName * -id AXSSRS –servicesAOSname AXServer –servicesAOSWSDLPort 8101

Here AXSSRS is the SSRS configurationID name and AXServer is the system name not AOS name.

Thursday, September 10, 2015

Add KPI to Role Center AX2012

It's easy to add KPI/Indicators to the Role Centers but it's a time consuming & tiring task to add multiple KPI/Indicators to the role center. But today I have found out a quick way to do so.

Firstly just add a KPI web part to the role center page.
Go to the Page Definition in AOT, right click on it and click "View Code". Then add a small piece of code just after the ending line of KPI webpart code:

&lt;ArrayOfIndicator xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"&gt;

After the above line add the below given code and change the Cube name & Indicator Name or other required properties of the KPI accordingly. Most importantly change the Id for every KPI.

&lt;Indicator&gt;
    &lt;Id&gt;ae413b36-9f55-40d5-ae21-a8d3ceaa83cc&lt;/Id&gt;
    &lt;CubeName&gt;General ledger cube&lt;/CubeName&gt;
    &lt;MeasureName&gt;Accounts receivable turnover&lt;/MeasureName&gt;
    &lt;DisplayTitle /&gt;
    &lt;SliceDimensionAttribute /&gt;
    &lt;TimePeriodsName /&gt;
    &lt;RolePlayingTimeDimension /&gt;
    &lt;ReportPath /&gt;
    &lt;ValueType&gt;Amount&lt;/ValueType&gt;
    &lt;IsDecreasingBetter&gt;false&lt;/IsDecreasingBetter&gt;
    &lt;Visible&gt;true&lt;/Visible&gt;
    &lt;IsValid&gt;true&lt;/IsValid&gt;
    &lt;EnableFilters&gt;false&lt;/EnableFilters&gt;
    &lt;DateFilters&gt;
      &lt;DateFilterItem&gt;
        &lt;DateTimeDimension&gt;Acknowledgement date&lt;/DateTimeDimension&gt;
        &lt;TimePeriod&gt;Current_KPI&lt;/TimePeriod&gt;
      &lt;/DateFilterItem&gt;
    &lt;/DateFilters&gt;
    &lt;NonDateFilters /&gt;
    &lt;ReportClientMenuItem /&gt;
    &lt;ReportWebMenuItem /&gt;
    &lt;CompareMeasureName /&gt;
    &lt;CompareMeasureCaption /&gt;
    &lt;SplitOrder&gt;Top&lt;/SplitOrder&gt;
    &lt;NonEmpty&gt;true&lt;/NonEmpty&gt;
    &lt;SplitCount&gt;10&lt;/SplitCount&gt;
  &lt;/Indicator&gt;

Wednesday, September 9, 2015

Ax2012 Number Sequence with year

Source:

http://dev.goshoom.net/en/2013/10/year-in-number-sequence/

Reset Number sequence Ax2012

Whenever you need to reset the number sequence in AX2012 you can use the below job code. You just need to pass the company name for which you want to reset.

static void resetNumSeq(Args _args)
{
    NumberSequenceTable numseqtab;
    info(curext());
    changecompany ('test')
    {
        ttsbegin;
        while select forupdate numseqtab
        {
            numseqtab.NextRec = numseqtab.Lowest;
            numseqtab.update();
        }
        ttscommit;
    }
}

Monday, September 7, 2015

Dynamics AX client crashing/closing automatically

Today I faced a very weird issue where Dynamics Ax client was getting closed just after displaying the splash screen. I thought maybe the client is corrupt so I tried reinstalling the Ax client but it didn't work.

I even tried clearing the AUC files, restarting AOS, restarting server but all went vain. And then I noticed that a windows service named "User Access Logging Service" was in stopped state. So I restarted it and things started working perfectly.

As the service was stopped so AX wasn't able to authenticate the user trying to login.

Install Sharepoint on non server machine

If you want to install Sharepoint on a non server OS i.e. Windows 7, Windows 8 then you can use below mentioned methods:

Sources:
http://www.disruptivei.com/Blogg/Inl%C3%A4gg/6/Install-SharePoint-2013-on-Windows-7-8-8-1

http://www.codeproject.com/Articles/155805/Install-Sharepoint-2010-in-a-non-Server-OS

Monday, August 31, 2015

Delete all transactions Ax2012

There is a class named "SysDatabaseTransDelete" in Axapta which can be used to delete all the transactions from your Ax Db but will not delete the base setups. In that case we can use the same DB as Production Db.
NOTE: It works perfectly with Ax2012 CU3 and above as it is now updated for new DB structure. Otherwise you may face issues with General Journal/Trial balance data.
It deletes all data from tables in the Transaction, WorksheetHeader and WorksheetLine table groups plus the following tables...
       SalesTable
       PurchTable
       WMSPallet
       CustInterestJour
       CustCollectionLetterJour
       ProjControlPeriodTable
       ProjInvoiceJour
       ProjJournalTable
       PdsRebateTable
       PdsBatchAttributes
You can run it from the AOT by right clicking on the SysDatabaseTransDelete class node and selecting "open" - this isn't the sort of thing you would want to put on a menu anywhere.
Here is a job for the same:
static void deleteTransactions(Args _args)
{
SysDatabaseTransDelete delete;
;
delete = new SysDatabaseTransDelete();
delete.run();
}

Friday, August 21, 2015

AX2012 R3: DIXF Could not load assembly error

While working on DIXF there can be scenario where you may face errors where assemblies are not able to load properly. Like below:

"Could not load file or assembly 'microsoft.dynamics.ax.framework.tools.dmf.previewgrid.dll'"

In this case you can use 2 options:

1. You can reinstall DIXF Client.
2. You can copy the dll file mentioned in the error from one AOS where it's working properly and paste it to the AOS where the error is coming. The file location is "C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin".

SSIS 2012: Access is denied error

While connecting to SSIS in SSMS, you may face an error of "Access is denied". It can be resolved by following the below steps:
  1. If the user is not a member of the local Administrators group, add the user to the Distributed COM Users group. You can do this in the Computer Management MMC snap-in accessed from the Administrative Toolsmenu.
  2. Open Control Panel, double-click Administrative Tools, and then double-click Component Services to start the Component Services MMC snap-in.
  3. Expand the Component Services node in the left pane of the console. Expand the Computers node, expandMy Computer, and then click the DCOM Config node.
  4. Select the DCOM Config node, and then select SQL Server Integration Services 11.0 in the list of applications that can be configured.
  5. Right-click on SQL Server Integration Services 11.0 and select Properties.
  6. In the SQL Server Integration Services 11.0 Properties dialog box, select the Security tab.
  7. Under Launch and Activation Permissions, select Customize, then click Edit to open the Launch Permissiondialog box.
  8. In the Launch Permission dialog box, add or delete users, and assign the appropriate permissions to the appropriate users and groups. The available permissions are Local Launch, Remote Launch, Local Activation, and Remote Activation. The Launch rights grant or deny permission to start and stop the service; the Activation rights grant or deny permission to connect to the service.
  9. Click OK to close the dialog box.
  10. Under Access Permissions, repeat steps 7 and 8 to assign the appropriate permissions to the appropriate users and groups.
  11. Close the MMC snap-in.
  12. Restart the Integration Services service.
Reference: https://msdn.microsoft.com/en-us/library/aa337083.aspx

Delete company in AX2012 using SQL

Sometimes we are not able to delete company from AX due to existing transactions then SQL comes to the rescue and does the job beautifully.

There is a Stored Procedure in "master" database named "sp_MSforeachtable". Use the below commands:


This will delete all the transactions from all the tables related to that particular company:


EXEC sp_MSforeachtable 'delete from ? where ?.DataAreaID = "CEU"'


This will delete the company name from the company list in AX:


DELETE FROM DATAAREA WHERE DATAAREA.ID 'CEU'

Thursday, July 2, 2015

Hide any file inside an image file

This a small steganography hack that is fun and sometime really useful,  when  you want to send some file over internet, but upload of only image  file  are allowed on that server.
First here is the definition of stenography from Wikipedia. 
Steganography   (Listen) is the art and science of writing hidden messages in such a   way that no one, apart from the sender and intended recipient, suspects   the existence of the message, a form of security through obscurity.  The  word steganography is of Greek origin and means “concealed writing”  from  the Greek words steganos (στεγανός) meaning “covered or  protected”, and  graphei (γραφή) meaning “writing”.    

In  short, when you  see the file it's just a normal image, but it has some  hidden message  inside it, or in general it can contain anything, even a  whole movie.

There  are lots of tools available for this  purpose, but we can do it using  what we already have just the command  prompt in windows.
The requirement
  • The image file
  • The file to be hidden, the zip file
  • Command prompt
The image I will be using is this


and I want to hide a Ms word file and a Pdf behind this image, Select both the file and send to a Zip file.

Steps..
  1. Place the zip file and the image in a folder , I am placing it on the desktop.
  2. Open   cmd(command prompt) and then go to the directory where both the files   are. Like for example, in this case, it's "desktop". So you might need   to type cd desktop 
  3. Now type copy /b imagefilename + zipfilename [filename with extensions], here is the image for clarity.
  4. Now   the size of the image will increase, what this is doing is simple,  just  appending the second file to the first file and that /b is to  specify  that it is a binary file.
Opening The file
After   copying, the image file size will only increase, but it can be opened   normally and no difference will be seen except the size. To open the  Zip  file, open this image with any Zip tool like 7zip, winrar, or winzip and you can find all the files there, just extract it wherever you want.

Creating wifi hotspot in Win7 or Win8

You don't need connectify or any other software for it. Also, you can save yourself from that 90 minutes counter in connectify. 

All you need to do is run the following two commands in cmd - 

Open cmd with Run as Administrator.

1) netsh wlan set hostednetwork mode=allow ssid=wifiname key=wifipassword

2) netsh wlan start hostednetwork

Best solution - Make a batch file of it and just run the file every time when you start the pc. 

To make a batch file -

First write the commands on a notepad

Then save it with the extension bat.  e.g. wifi.bat

Your batch file is made and now execute the file with Admin Privileges.

Important - For this to work, your sharing should be on in network properties for   the network/ethernet connection that you want to share through your   wifi:

Go to Open Network and Sharing Centre ->Change Adapter Settings(On left panel)

Your wifi hotspot would be Microsoft Hosted Network Virtual Adaptor in the Network Connections.

Go to the properties of the LAN/ethernet/WiFi connection and make the changes accordingly.





Your wifi hotspot would be ready. :)

To stop the wifi hotspot - 
Write the following in command prompt : netsh wlan stop hostednetwork.

For those having trouble with creating hotspot on their dongles:
If you have tried the above steps and its still not working for you then you will have to unlock your dongle. Unlocking simply means downloading any other third party dialer which will work on all network operators.

Just   change the file format [(mp3|wma|aac|flac) part] to your required   format and you will get a search result of sites containing direct   download links to your search query. Enjoy!

View restricted content in Youtube

For the best experience, full screen is the best mode, but it has an inherent drawback that we can't switch to other tabs during this mode with one click.

The remedy is to replace "watch?v=" with "v/" in the video URL, to get the full screen tabbed viewing mode:


For example
instead of: www.youtube.com/watch?v=7z9NUV_YrOo&feature=relmfu, type: www.youtube.com/v/7z9NUV_YrOo&feature=relmfu.

You can also use this trick to view the restricted content, without signing in!

Download Videos

Some sites don't allow to download their video content without signing in or do not have facility to download at all.

So without using any extension or downloader, here is how to do this..


  1. Goto that page.
  2. Press ctrl+shift+i or right click and select Inspect Element.
  3. Select the Network tab and refresh the page & play the video to get content status.
  4. You can sort the content by TYPE (tab), to easily get the video link at the bottom under the NAME(tab).
  5. Double click the video link. Voila, your download will start.
Works fine with many sites. Enjoy :)