Monday, 20 June 2016

How to update SID, Network domain and Network alias after restoring new DB in AX

Issue "Failed to logon to Microsoft Dynamics AX" after restoring demo/ other network domain data into SQL 

Here, We will discuss about the issue "Failed to logon to Microsoft Dynamics AX". 
Generally when we install new AOS then "MicrosoftDynamicsAX" is our default database and after synchronization/compilation we can access our AOS instance. After completing this approach we need data to start practice or work. 
So I would recommend to create new database (suppose "MsDyDemo") in your SSMS instead of overwriting over your default DB. What I mean to say, don't touch your default database (MicrosoftDynamicsAX). Now restore demo data or other network domain's data into your newly created database "MsDyDemo" and go to: Administrative tools/Microsoft Dynamics AX 2012 Server Configuration/Database connection (tab). Select "MsDyDemo" under Database name drop down and restart AOS services. Once AOS services is running then you need to access Ms Dy AX but you will get info message "Failed to logon to Microsoft Dynamics AX" in case your system domain and restored DB domain are different.

Here, for fixing this issue we need to change SID, Network domain and Alias from restored DB "MsDyDemo" so first select your default DB "MicrosoftDynamicsAX" and run SQL query 
select * from USERINFO
execute this query and select user- "Admin". Copy SID, Network domain from Admin user and save in separate Note pad or Word document. 



Now select and expand database "MsDyDemo", expand tables and select dbo.UserInfo. Right click on table dbo.UserInfo and select "Edit Top 200 Rows". 

Select User- Admin and update SID, Network domain values from Note pad or Word document (the values which we copied from default DB) and give your current user account name under NetworkAlias. Save the changes and run AOS with admin credential. Once AX gets open then go to: Systemadministration/Common/Users/Users/Import other user accounts.

I hope I cleared the concept.

Happy DAXing..... 

Update SID through SQL query

Update SID after restoring DB into AX

UPDATE USERINFO SET SID = '', NETWORKALIAS = '', NETWORKDOMAIN = '', NAME = ''


UPDATE SYSBCPROXYUSERACCOUNT SET SID = '', NETWORKALIAS = '', NETWORKDOMAIN = ''


UPDATE SYSUSERINFO SET SQMUSERGUID = '00000000-0000-0000-0000-000000000000'


DELETE FROM SYSSERVERCONFIG
DELETE FROM SYSSERVERSESSIONS
DELETE FROM SYSCLIENTSESSIONS
DELETE FROM SRSSERVERS
DELETE FROM BATCHSERVERCONFIG
DELETE FROM BATCHSERVERGROUP
DELETE FROM SYSUSERLOG
DELETE FROM BICONFIGURATION
DELETE FROM BIANALYSISSERVER
DELETE FROM SMMPHONEPARAMETERS
DELETE FROM EPGlobalParameters
DELETE FROM EPWebSiteParameters

Monday, 25 April 2016

Configure document management [AX 2012] Error: while doing attachment "Document management dictionary does not exist"

Configure document management [AX 2012]

Updated: July 7, 2014
Applies To: Microsoft Dynamics AX 2012 R3, Microsoft Dynamics AX 2012 R2
This topic explains how to configure document management for the first time. You can use document management, also known as document handling, to attach notes, documents, or document references to records. You can also use Office Add-ins for Microsoft Dynamics AX to integrate with document management and create Microsoft Word and Microsoft Excel documents or document templates that use Microsoft Dynamics AX data.
The following illustration shows how to configure document management. The numbers correspond to the procedures later in this topic.
The configure document management process

1. Activate document management
Before you can attach documents to records or generate documents from a record, you must activate the document management functionality and then you must activate document management for specific tables.
To activate document management, follow these steps:
  • Click File > Tools > Options. 
  • In the General area, expand the Miscellaneous FastTab.  
  • In the Document handling field group, select the Document handling active check box.
To activate document management for specific tables, follow these steps:
  • Click Organization administration > Setup > Document management > Active document tables. 
  • Click New. 
  • Select the name of the table to activate document management for.  
  • Example: To activate document management for sales orders, select the SalesTable table name.
  • Repeat steps 2 and 3 for each table that you want to activate document management for.

When you attach a document to a record in Microsoft Dynamics AX, it is stored in a location that you specify. This location is called an archive directory. You can specify one archive directory for all the document types you set up, or you can specify a separate archive directory for each document type. If you don’t specify an archive directory for a document type, the document type uses the archive directory that you specify in this procedure. See “Create or import document types” later in this topic for more information about how to specify an archive directory for a document type.
NoteNote
If you use Enterprise Portal for Microsoft Dynamics AX, there are additional requirements and restrictions about document archives. For more information, see Set up documents for viewing in Enterprise Portal.
To specify a location for the Microsoft Dynamics AX document archive directory, follow these steps:
  • Click Organization administration > Setup > Document management > Document management parameters.
  • In the General area, browse to the location of the archive directory.
    Caution noteCaution
    If you already have an archive directory specified and you want to change it, you first must move the contents of the existing archive directory to the new archive directory. For more information, see Document management.
  • Optional: Specify the maximum file size that is allowed for documents.
    Field Description
    Max. file size in database Enter the maximum file size, in megabytes, for a file that is saved to the Microsoft Dynamics AX database.
    Max. file size in file system Enter the maximum file size, in megabytes, for a file that is saved to the archive directory location.

Before you can use document management, you must specify number sequences for documents. The files that you attach to records are renamed when they are stored in the archive directory. The file name of the attached files is determined by the number sequences that you set up for documents.
To specify number sequences for documents, follow these steps:
  • Click Organization administration > Setup > Document management > Document management parameters.
  • In the Number sequences area, select a number sequence code for each reference. If the number sequence code that you’re looking for is not listed, you must create a new number sequence code in the Number sequences list page. For more information, see Set up number sequences.

You can control which types of files, or documents that have specific file name extensions, that users can attach to Microsoft Dynamics AX records.
To specify file types, follow these steps:
  • Click Organization administration > Setup > Document management > Document management parameters.
  • In the File types area, review the default file types. Remove the file types that users should not be able to attach to records, and add any additional file types that users should be able to attach to records.

When you use document management, you can integrate with Office Add-ins to create Word documents and Excel workbooks that are linked dynamically to the tables in Microsoft Dynamics AX. For specific instructions about how to do this, see Install Office Add-ins and Set up integration with Microsoft Office Add-ins.

Document types are required for document management and are used to categorize the documents that you attach to records. When you create an unattached document, one of these content types is assigned to it. If you have workflows set up, workflow uses the document type to route the document to the appropriate user or work-item queue.
The Note and File document types are available by default.

To create a document type, follow these steps:
  • Click Organization administration > Setup > Document management > Document types.
  • Click New, and then enter the following information about the document type.
    Field Description
    Class Select the action that occurs when a user creates an attachment of the selected document type:
    • Attach URL – Attach a reference to a document by using a URL.
    • Create a Microsoft Excel worksheet by using COM – Create an Excel worksheet and copy data from the selected transaction.
    • Create a Microsoft Word document by using COM – Create a Word document and copy data from the selected transaction.
    • Create application document – Create a Word document without opening Word.
    • Simple note – Create a simple note for the referenced transaction.
    • Template library – Create a template file by using Word or Excel, and then save the file to a template library. For example, you can create a budget template by using Excel. Each department in your organization then enters budget information in a copy of the template.
      NoteNote
      Your system administrator must create the site or SharePoint document library for the template library.
    Group Select the group for the document type.
    Auto-save Select this check box to automatically save temporary files to the database after you use them.
    Typically, temporary files are stored in the Temp folder in Microsoft Windows. To save temporary files in the directory that is specified in the File location list, select Auto-save.
    Autodelete Select this check box to automatically delete temporary files after you use them.
    Typically, temporary files are stored in the Temp folder in Windows.
    Remove Select Document only to remove only the reference to the document file or select Document and physical file to remove both the reference and the physical file.
    Ask for confirmation Select this check box to require confirmation before the physical file is deleted.
    Category Select an Enterprise Portal document category to associate with the document type.
    Details for document categories are set up in the Enterprise Portal parameters form. For more information, see Attach documents, notes, or URLs to records.
    Archive directory The directory where document files of the selected document type are stored.
    If this field is empty, the default archive directory that is specified in the Document management parameters form is used as the archive directory.
    NoteNote
    If you use Enterprise Portal, there are additional requirements and restrictions about document archives. For more information, see Set up documents for viewing in Enterprise Portal.
    Location Select the location where document files for this content type are stored. The following options are available:
    • Archive directory – Documents of this type are stored in the directory that is specified in the Archive directory field.
    • Database – Documents of this type are stored in the Microsoft Dynamics AX database.
    • Original location – Documents of this type are stored in the location that was used when the file was originally attached to the record.
    • SharePoint – Documents of this type are stored in a SharePoint document library.
    NoteNote
    If documents are stored in a shared location instead of the database, verify that the correct access level is set for the shared location.
    Check table If this check box is selected, the selected document type is available only from the tables that are specified in the Options form.
    By default, the check box is cleared for the standard document types, Note and File.
    For more information, see Restrict a document type to a specific table.

To import document types, follow these steps:
  • Click Organization administration > Setup > Document management > Document types.
  • Click Import.
  • Browse to the location of the file that contains the exported document types.
  • When prompted to delete tables before you import, click Yes to all, and then click OK.
  • Click Yes to confirm.

Content types are used to categorize documents that are not attached to records. Examples of unattached documents might be invoices, expense reports, or purchase orders. Workflow uses document content types to route documents to the correct user or work-item queue for processing. For more information, see Configuring the workflow system.
To create content types, follow these steps:

  1. Click Organization administration > Setup > Document management > Document content types.
  2. Click New, and then enter a name and a description for the content type.
For more information, see Document content types (form).

Before you can use Application Integration Framework (AIF) document services, you must specify document management settings for AIF. AIF document services are query-based services that you can use to exchange data with external systems by sending and receiving XML documents. These documents represent business entities, such as customers, vendors, or sales orders. To specify document management settings for AIF, follow these steps:

  1. Click Organization administration > Setup > Document management > Document management parameters.
  2. Click AIF.
  3. Complete the following fields.
Field Description
Document type: Select the document type for notes in incoming electronic documents. For sales orders, this type must be Note.
Document file service Select this check box if the web service document files should be submitted to workflow for routing to appropriate parties.
For more information, see AIF Document Services

Error: Document management dictionary does not exist

For Example: In AX 2012 I am trying to attach or upload file, then I am facing an error i.e.
"Document management dictionary does not exist"

Solution:
  • Organization administration > Setup > Document management > Document management parameters, specify the default archive directory..
  • Organization administration > Setup > Document management > Document types, select the specific document type and specify the archive directory.
For Example: I am also getting the issue while changing the Product image and did the same exercise, but no use..!! And my archive directory is already selected but still m getting the same issue. Kindly advise.

Solution:
Document Management Parameters: Select and copy an Archive Directory path
Document types: click create new, for example Image and select also Image as the "Group" on the right hand of the form.
You'll find the forms here: Organization administration > Setup > Document management
After that I was able to attach an item under Product information management/Common/Released products > "Product tab" - Product Image
 

Happy DAXing....

Thursday, 10 March 2016

Dynamics AX 2012 - Workflow Development in 2 Hrs.

Hi Friends,

First of all would like to wish you all Very "Happy and Dynamics new year -2012".

You all might be aware/heard of new changes related to worklow architecture and development.
So this post basically addresses,

1. Workflow Architecture changes
2. Workflow Development  wizards
3. Generic class for submit/resubmit events on all workflows in AX.


1. Workflow Architecture changes

In 2012, AOS service has gone tremendous changes like

- Now you can directly host WCF services on AOS.
- Earlier version we were using IIS to interact with WWF(Windows workflow foundation) and    
           WCF (Windows communication foundation).
- Because of above change, now no need to install workflow component separately
- Just run the workflow configuration wizard (available in System administration->Setup)
- Workflow templates/configuration were made available across companies/per company level.
- Workflow template is renamed to Workflow types

2. Workflow Development through wizards.

Let us develop workflow for
        'Customer approval- New created customer should be approved through workflow'

Step 1:
          Create a query for custTable say 'CustApprWorkflowQry' in AOT->Queries

Step 2:
          Duplicate enum 'PurchReqWorkflowState' and rename it to 'CustApprWorkflowState' and drag it to CustTable Table.

Step 3:
          Override 'canSubmitToWorkflow' method on Table->CustTable and paste below code.

  //BP Deviation Documented
                public boolean canSubmitToWorkflow(str _workflowType = '')
                {
                    boolean ret;

                    ret = this.RecId != 0 && this.CustApprWorkflowState ==
                    CustApprWorkflowState::NotSubmitted;

                    return ret;
                 }


Create new method on CustTable as below to update worklow state during its life cycle.

                //BP Deviation documented
                public static void UpdateCustWorkflowState(RefRecId _recId, CustApprWorkflowState _state)
                {
                    CustTable custTable = CustTable::findRecId(_recId, true);

         ttsBegin;

         custTable.CustApprWorkflowState = _state;
         custTable.update();

         ttsCommit;
  }


Step 4:
            Create workflow type (template/configuration) through wizard available in 2012.

  Run wizard as below:

  AOT->Workflow-> Workflow types  (Right click ->Add-Ins-> workflow type wizard...

  Specify values as shown in below image







  Click on next, as shown in below image wizard will create workflow eventhandlers class and menu items for you.




  Paste below code to update workflow state.

  //BP Deviation Documented
  public void started(WorkflowEventArgs _workflowEventArgs)
  {
      CustTable::UpdateCustWorkflowState(_workflowEventArgs.parmWorkflowContext().parmRecId(), CustApprWorkflowState::Submitted);
  }

  //BP Deviation Documented
  public void completed(WorkflowEventArgs _workflowEventArgs)
  {
     CustTable::UpdateCustWorkflowState(_workflowEventArgs.parmWorkflowContext().parmRecId(), CustApprWorkflowState::Completed);
  }

  //BP Deviation Documented
  public void canceled(WorkflowEventArgs _workflowEventArgs)
  {
  CustTable::UpdateCustWorkflowState(_workflowEventArgs.parmWorkflowContext().parmRecId(),   CustApprWorkflowState::PendingCancellation);
  }


Step 5:
           Create workflow approval through wizard available in 2012.
 
  Run wizard as below:

  AOT->Workflow-> Approvals  (Right click ->Add-Ins-> Approval wizard...

  Specify values as shown in below image




  Click on next, as shown in below image wizard will create workflow element eventhandlers and menu items for you.




  Paste below code to update workflow state.

  //BP Deviation Documented
  public void started(WorkflowElementEventArgs _workflowElementEventArgs)
  {
     CustTable::UpdateCustWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(),   CustApprWorkflowState::Submitted);
  }

  //BP Deviation Documented
  public void returned(WorkflowElementEventArgs _workflowElementEventArgs)
  {
     CustTable::UpdateCustWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(),  CustApprWorkflowState::Returned);
  }

  //BP Deviation Documented
  public void changeRequested(WorkflowElementEventArgs _workflowElementEventArgs)
  {
          CustTable::UpdateCustWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(),  CustApprWorkflowState::ChangeRequest);
  }

  //BP Deviation Documented
  public void completed(WorkflowElementEventArgs _workflowElementEventArgs)
  {
    CustTable::UpdateCustWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(), CustApprWorkflowState::Approved);
  }

  //BP Deviation Documented
  public void canceled(WorkflowElementEventArgs _workflowElementEventArgs)
  {
         CustTable::UpdateCustWorkflowState(_workflowElementEventArgs.parmWorkflowContext().parmRecId(),  CustApprWorkflowState::PendingCancellation);
  }

Step 6:
          Enable workflow on CustTableListPage form and alos drag field CustApprWorkflowstate on form overview grid, as below

          CustTableListPage->Design, set properties as below




Step 7:
          Download below class to activate workflow on submit and resubmit.

          This is generic class and with little modification can be used for all different worklow's in AX.
          Download Class XPO :
       
         Once you download and import class,  change below menu-items associated with submit and resubmit actions.




Step 8:
          Run Incremental CIL generation, AOT->Right click-> Incremental CIL generation

You are done with development and can configure workflow in AR->Setup
After activating above workflow configuration test it by creating new customer in CustTableListPage form.

Hope you enjoyed this new style of  workflow development which will take 1-2 hours for any new basic  workflow approval :)










Happy DAXing
........

Increase report running time to fix time out issue



Happy DAXing
...........

How to handle SSRS reports which will take long time

Error: Running the report has been cancelled due to the time it will take to run. Adjust the parameters of the report and retry.

We know that there are/will be some reports which will take more time to render due to the many rows/transactions. This post will help you to show appropriate warning/error messages to the end user while running the report. 

The number of records that are processed by report might be large and the user experience will be affected, because the client will be locked up if printing to the screen. 

In this case, you might want to return a warning message to the user that indicates that time to process the report might be long and confirm that they want to run the report. 

Another case could be where the number of records being processed is very large and a time-out might occur in report processing and clearly we should not run this report.
In this case, we should not run the report and therefore, should return an SrsReportPreRunState::Error enumeration value with the error message. 
In AX 2012, SSRS reports , through SrsReportRunController we can easily let the user know that the report will take more time with warnings or error messages through preRunValidate method. 


Example-1 : Trial balance report

Take the standard example of Trial balance report from General Ledger >> Reports >> Transactions >> Trial balance.

Use standard LedgerTrialBalanceController class to help you understand preRunValidate method: this validates container before running the report. Override this method to do custom pre-validation for any report. Typical use of this method will be to validate if the time taken to run the report is acceptable.
In this standard example: If the query is going to retrieve more than 1000 rows, a confirmation Box will be displayed to the user as shown below.

Clearly in the below standard example : warning limit is 1000 and error limit is 100000.
 

Run this report as shown below...
 

Here comes the confirmation Box: 
If your report is long running, it may time-out. Do you want to continue? 

Note: In order to resolve/by pass this confirmation Box, a developer can change the macro #define.warningLimit to greater value 
Example : #define.warningLimit(2000); 

image

Let us run the report One more time as shown below. 


Here comes the error message: Running the report has been cancelled due to the time it will take to run. Adjust the parameters of the report and retry. 
In order to resolve this problem, Increase the ErrorLimit macro value from 100000 to 150000 or 250000 in the preRunValidate method. 
Please note, it is not recommended to increase as it will take more time and your box cannot handle load. 

Example : #define.ErrorLimit(250000); 

image


I would recommend that to be Compiled forward this LedgerTrialBalanceController class and then run Generate Incremental CIL and then restart SSRS services. Now run the Trial balance report, it should give output. 
In case, above error is still occurring then run Generate Full CIL and then restart SSRS services. Now run the Trial balance report, it must give output.

Example-2 : General Journals report 

Take the standard example of Print journal from General Ledger >> Reports >> Journal >> Print journal. 

Use standard LedgerJournalController class to help you understand preRunValidate method: this validates container before running the report. Override this method to do custom pre-validation for any report. Typical use of this method will be to validate if the time taken to run the report is acceptable. 
In this standard example: If the query is going to retrieve more than 1000 rows, a confirmation Box will be displayed to the user as shown below. 

To get the confirmation box and for the sake of the demo/understanding: I have hardcoded the rows count to 1001 as shown below. There is a new static method in QueryRun::getQueryRowCount that will get the row Count of the query. 

Please note: Remove hardcoded values later. This is hardcoded only for the sake of demo/Walk through 
Clearly in the below standard example : warning limit is 1000 and error limit is 100000.

image

Run this report as shown below...

image

Here comes the confirmation Box: 
If your report is long running, it may time-out. Do you want to continue? 

Note: In order to resolve/by pass this confirmation Box, a developer can change the macro #define.warningLimit to greater value 
Example : #define.warningLimit(2000); 

image

you can increase the row count : to 1000001. 

image

Let us run the report One more time as shown below. 

image

Here comes the error message: Running the report has been cancelled due to the time it will take to run. Adjust the parameters of the report and retry
In order to resolve this problem, Increase the ErrorLimit macro value in thepreRunValidate method. 
Please note, it is not recommended to increase as it will take more time and your box cannot handle load. 

Example : #define.ErrorLimit(150000); 

image

Happy DAXing
.............

SSRS Report – Timeout error for Long running queries in AX2012

A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 202.xx.xx.xx:80

Posted on August 6, 2013 by Siva Kumar
There is a process to change long running jobs so that they are run in a Pre-Processing way, so that all the data is prepared before the SSRS Report Window is started. This prevents the timeout problem, sometimes shown by the message
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond
To change the report to run in this pre-processing way (Similar to Sales confirmation, Sales Invoice, etc. reports).
see this example below for the Fixed Asset movement report on how to change this:
1. To find which object you need to modify, first look in the AOT >> Menus, for the Menu where the report is
2. View the properties on this to see the associated menu item. You can see below the menu item is “AssetBalancesPeriod”.
3. Find this menu item in AOT >> Menu Items >> Output and look at the properties, make a note of the “LinkedPermissionObject”, in this case “AssetBalancesPeriod”
4. Next in the AOT >> SSRS Reports >> Reports, locate AssetBalancesPeriod, then expand this out until you see the Server Methods. Make a note of the Server Method class, in this case “AssetBalancesPeriodDP”
5. In the AOT >> Classes, locate and open class AssetBalancesPeriodDP.
6. In the AssetBalancesPeriodDP\classDeclaration, change the extend class to SrsReportDataProviderPreProcess instead of SrsReportDataProviderBase
7. Make a note of the Temp table used in the report, as above this is AssetBalancesPeriodTmp.
8. Next, change the method AssetBalancesPeriodDP\processReport to add the following line after the contract:
contract.parmFromDate();
contract.parmtodate();
AssetBalancesPeriodTmp.setConnection(this.parmUserConnection());
9. Next, in AOT > Data Dictionary > Tables, locate the table you made a note of in point 7, so in this case the AssetBalancesPeriodTmp. Change the table properties as follows:
• TableType = Regular
• CreatedBy = Yes
• CreatedTransactionId = Yes
10. Opened AssetBalancesPeriod report in Visual Studio and refreshed the data source to include new field (CreatedTransactionId).
11. Deployed the new AssetBalancesPeriod report.
12. In AX did a Generate Incremental CIL.
13. Restart SSRS
Now this report can run without timeout error.



Happy DAXing
................