Wednesday 28 December 2011

Close AXAPTA with X++ , shut down AX with X++ code


static void ShutDownAxapta()
{
    SysGlobalCache  cache = appl.globalCache();
    info            info;
    ;

    cache.set(classstr(info), identifierstr(Autologoff), true);

    info = new info();
    info.shutDown(true);
}

Tuesday 27 December 2011

How to manually deploy ODC Files to Microsoft Dynamics AX 2009 Enterprise Portal


Sometimes you may come across an issue with deploying ODC files from "AX2009 ->Administration -> Setup -> Business Analysis -> OLAP -> OLAP Administration" for various reasons and you have already tried the suggestions given in this link, then you can follow through the following manual steps to deploy them to the Enterprise Portal Server:

1. The ODC files are deployed to the Data Connections page on the Enterprise Portal site. By default, the Data Connections page is located at: http://[your ep hostname]/sites/DynamicsAx/Data%20Connections/Forms/AllItems.aspx
Verify if the files, definitely do not exist.
2. Download the attached AX2009_ODC_Files.zip and extract its contents to an empty folder. This contains 11 default ODC files.
3. Open the extracted ODC files with Notepad or any other text editor.
4. Edit all the odc files and replace the values in <odc:ConnectionString> to reflect your OLAP Server/Instance name and Database name:
Data Source=[Specify Your OLAP ServerName]
Initial Catalog=[Specify Your OLAP DbName]
ALSO, consider adding SSPI=Kerberos; to the ConnectionString, ONLY if you have configured Role Centers to useKerbersos Authentication (given in bold below):


<odc:Connection odc:Type="OLEDB">
<odc:ConnectionString>Provider=MSOLAP.3;Integrated Security=SSPI;Persist Security Info=True;DataSource=[YourOLAPServerName];Initial Catalog=[YourOLAPDbName];SSPI=Kerberos;</odc:ConnectionString>
… 
For example, if your OLAP Server name is Server1 and the OLAP database name is “Dynamics AX” and you have Kerberos Authentication configured then the <odc:ConnectionString> should look like this:
<odc:ConnectionString>Provider=MSOLAP.3;Integrated Security=SSPI;Persist Security Info=True;Data Source=Server1;Initial Catalog=Dynamics AX;SSPI=Kerberos;</odc:ConnectionString>
5. Save the changed ODC files.

6. If required, rename the ODC files names to match your OLAP database name, if not using the default database name "Dyanmics AX". By default the file naming structure is [OLAP Database name][space][Cube name].ODC, and there is also a default .ODC file just named as [OLAP Database name].ODC.
NOTE: The [OLAP Database name] is determined from what is specified in the "OLAP Administration" form under the "OLAP databases" tab (AX2009 ->Administration -> Setup -> Business Analysis -> OLAP -> OLAP Administration)
7. Browse to your Enterprise Portal site main site. 
8. Click on Site Actions > Site Settings. 
9. Under Galleries, click on Master pages. 
10. Click on View all site content (top left). 
11. Click on Data Connections folder (or alternatively browse to the Data Connection page, by default this is located at http://ServerName/sites/DynamicsAx/Data%20Connections/Forms/AllItems.aspx). 
12. Import all the edited ODC files.

AX2009_ODC_Files.zip

Thursday 22 December 2011

Matrix on Form - Axapta


Matrix on Form - Axapta


Hi,

This article describes how to achieve Data Represent in Matrix.
Sample Example – Want to display the total number of customers Currency Code and Customer Group wise.


To achieve this we can use Table contol on form.

How to Achieve:
  1. Create a form, and insert table control in the design. 
  2. Set AllowDecleration to Yes.
  3. Insert Int field, and Set AllowDecleration to Yes.


4.       Declare Global objects.


 5. Run method

 6.       Initvalues()

7.       getNoOfCust()


 8.       After performing all this, you also need to override editControl() method of Table Control.

Wednesday 21 December 2011

Managing Record-Level Security Dynamics Ax 2009


Record-level security builds on the restrictions enforced by user group
permissions. With user group permissions, you restrict which menus, forms, and
reports members of a group can access. Record-level security enables you to
restrict the information shown in reports and on forms.
Record-level security is commonly used in the following situations.
You can:

•  Allow members of a Sales user group to see only the accounts they
manage.
•  Prohibit financial data from appearing on forms or reports for a
specific user group.
•  Prohibit account details or account IDs from appearing on forms and
reports for a specific user group.
•  Restrict form and report data according to location or country/region.

Before You Begin

The process of setting record-level security involves selecting a database table in
the Record Level Security wizard. Tables store the data shown in reports and on
forms. You might find it helpful to work with a developer who has knowledge of
the database tables while configuring record-level security. The developer can
help you choose the table that directly corresponds to the report or form elements
to which you want to restrict access.
Also, verify the following before beginning:

•  Does the user group that will be assigned record-level security
already exist or do you need to create a new user group?

•  Does the user group have, at the very least, View permission for the
report or form? If, for example, a Finance user group does not have
any access permission for the General Ledger module, then it does
not make sense to assign record-level security to any report or form
in that module because the group cannot access those reports/forms
in the first place.

To Set Record-Level Security
Setting record-level security is a two-part process. The first part involves
selecting a user group and the appropriate database table using the Record Level
Security wizard. The second part involves creating a query that specifies the
fields and criteria to be applied when record-level security is enforced.

Record Level Security Wizard

This procedure shows you how to use the Record Level Security Wizard:

1. Click ADMINISTRATION → SETUP → SECURITY → RECORD LEVEL
SECURITY.
2. Press CTRL + N to open the Record Level Security (RLS) wizard.
3. Select a user group and click Next.
4. Select a table. By default, the most frequently accessed database
tables are shown. Click Show all tables to expand the selection.
Click Next.
5. Click Finish.

Procedure  Set up a Query
This procedure shows you how to set up a query:

1. In the Record level security dialog box, select the user group and
click Query. The Inquiry dialog box appears. The Range tab shows
some of the common fields for the specified table. Your objective on
this tab is to specify the exact fields to be shown to the selected user
group on the report or form.

2. Select the first item listed on the Range tab. If no item is listed, press
CTRL + N.

3. Use the Field drop-down menu to select the field you want to show
on the form or report.

4. Use the Criteria drop-down menu to select the criteria for the
designated field. If no drop-down menu appears, enter the designated
criteria.

5. As necessary, press CTRL + N to add additional fields and criteria.

6. Click OK.

7. Inform members of the selected user group that they must close their
current client sessions and start a new session. If necessary, end
active sessions from the Online users form.

8. Verify that record-level security is enforced on the desired report or
form by logging on to Microsoft Dynamics AX as a member of the
specified user group. You should see only the information specified
in the query for the designated criteria. If you see additional
information, verify your query.

Thursday 15 December 2011

Setup and Configuration of the Workflow for Microsoft Dynamics AX 2009 Administration


Workflow prerequisites

Before we begin installing and setting up Workflow, you will need to have administrator privileges on the machines in which you are installing Workflow on. The following prerequisites are required:
  • Internet Information Services (IIS) 7
  • .NET Framework 2.0
  • Business Connector
The Workflow component for Dynamics AX utilizes the Business Connector to communicate directly to Dynamics AX from its web service. Although it depends on the number of users and computing resources available, it is best practice to implement the Workflow web service application on its own server.

Workflow accounts setup

The Workflow system in Dynamics AX utilizes two accounts to function properly. If these accounts are not specified, workflow will still function; however, it is best practice to have dedicated accounts. One account is the service account. This account is responsible for the communication between Dynamics AX and the Workflow web service. The other account is the execution account. This account is responsible for executing Workflow tasks and processes. Similar to the Business Connector proxy account, these two accounts must be created with the following criteria:
  • The password must never expire
  • It must not be interactive
  • It must not be associated to any Dynamics AX users
Once the Workflow accounts have been created, the next process is to ensure that the Dynamics AX Workflow system will use the accounts. To do this, perform the following steps:
  1. Log in to Dynamics AX 2009.
  2. Go to Administration | Setup | Security | System service accounts.
    Microsoft Dynamics AX 2009 Administration
  3. In the System service accounts form, specify the Workflow System Account and theWorkflow Execution Account. To specify the accounts that were created in the Active Directory, mark the Alias field radio boxes. When complete, click on the OK button.
    Microsoft Dynamics AX 2009 Administration
Now that the Workflow accounts have been specified, the Dynamics AX Workflow system can utilize these accounts when communicating with the Workflow web service. It is also possible to create a user within Dynamics AX but not Active Directory, and use the Dynamics AX user accounts as the Workflow Service and Execution accounts. These accounts may appear as different users in Dynamics AX; however, these accounts will be impersonated by the AOS service account to the Workflow web service. This can make troubleshooting and connection auditing more difficult and therefore, it is not recommended.

Installing Workflow

Since Workflow consists of various parts that function together to create the Dynamics AX 2009 Workflow system, we will break down each part’s setup and complete each setup individually.

Creating a website for Workflow

Before we can install the Workflow extended server component, we must have a website available to install upon. It is possible to use the default website that is on port 80. However, it is not recommended; therefore, a new website must be created. For information regarding how to create a website in IIS 7, refer to http://technet.microsoft.com/en-us/library/cc772350(WS.10).aspx.

Installing the Workflow component

By now you should be accustomed to the process of installing the extended components for Dynamics AX. Installing Workflow is no different. The following steps will guide you through the process:
  1. Run the Microsoft Dynamics AX Setup wizard to add new components. In the Add or modify components screen of the wizard, mark the Workflow checkbox, as shown in the following screenshot and then click on the Next button:
    Microsoft Dynamics AX 2009 Administration
  2. In the following screen of the wizard, specify the password for the .NET Business Connector proxy account, and then click on the Next button:
    Microsoft Dynamics AX 2009 Administration
  3. The Domain\user name field will automatically be populated if the Business Connector proxy user is specified in the Administration | Setup | Security | System service accounts form in the Business Connector Proxy group.
  4. In the next section of the wizard, you will be prompted to tweak the Workflow service. In other words, you can select which website you want to install the Workflow service into. By default, the wizard will select the default website in IIS. However, it is recommended to install Workflow on its own dedicated site and port, you have the flexibility to do so. When you are satisfied with the settings on this page, click on the Next button.
    Microsoft Dynamics AX 2009 Administration
  5. In the following screen you will be prompted to specify the AOS account for the Workflow service to grant permissions to. If there is more than one AOS and each AOS service account is different, provide the accounts for each AOS so that they can access the Workflow service.
    Microsoft Dynamics AX 2009 Administration
  6. In the following step, you are prompted to complete the installation of the Workflow by clicking on the Finish button. You will want to restart IIS after the Workflow has been successfully installed. Therefore, leave the option checked at the bottom, as shown in the following screenshot:
    Microsoft Dynamics AX 2009 Administration
  7. Once installed, you will be prompted with the final screen. The final screen will display the result of the installation of the Dynamics AX 2009 Workflow system. If the installation is successful, you will see a green box next to the installed component. Otherwise, if the box is orange or red, you should open the log file after you close the wizard by marking the checkbox at the bottom.
    Microsoft Dynamics AX 2009 Administration

Enabling Workflow in Windows Server 2008 R2

In Windows Server 2008 R2, additional setup is required to enable the Workflow web service. The Workflow web service application pool must be enabled to run 32-bit applications. Otherwise, the Workflow service will fail. To set up the application pool to run 32-bit applications, perform the following steps:
  1. Go to the IIS console and access the web server that you installed the Workflow web service on.
  2. Under &ltYour web server&gt | Application Pools, select the Dynamics AX Workflowapplication pool.
    Microsoft Dynamics AX 2009 Administration
  3. Under Actions, go to Advanced Settings.... In the Advanced Settings window, set the Enable 32-Bit Applications property to True. When complete, click on the OK button to save the changes.
    Microsoft Dynamics AX 2009 Administration
After performing these steps, the Workflow web service can then be used by Dynamics AX to process Workflows. Next, we will set up Dynamics AX to use the Workflow web service.

Setting up Workflow

Now that the Workflow service for Dynamics AX has been successfully installed, we can begin to configure it for use. Dynamics AX will not utilize the Workflow service after it has been installed. Therefore, in order to properly configure the Workflow system, we must do so within Dynamics AX 2009.

Workflow configuration prerequisites

Before we begin configuring the Workflow system, we need to ensure that the following is set:
  • A dedicated Workflow batch group has been created
  • An AOS is set up as a batch server
Creating a dedicated batch group is not required but recommended since, there is no batch group dedicated for Workflow. Since Workflow uses batch jobs to generate notifications and run Workflow processes, a batch server is required.

Creating a dedicated Workflow batch group

The following steps cover the process of verifying whether an AOS is a batch server and how to create a Workflow batch group:
  1. To create a dedicated Workflow batch group, go to Administration | Setup | Batch groups.
    Microsoft Dynamics AX 2009 Administration
  2. Create two new records in the Batch group form—one group that will execute Workflow commands and another that will process Workflow due date notifications.
    Microsoft Dynamics AX 2009 Administration

Setting up the AOS as a batch server

Since Dynamics AX workflow uses a batch job to send workflow tasks to the web service in order to be processed in Dynamics AX, we need to ensure that there is at least one AOS that is designated as a batch server. Without the batch job, the Workflow web service would sit idle, waiting for a workflow request even though a user may have initiated a workflow task in Dynamics AX. In this section, we will cover the process of setting up an AOS as a batch server and ensuring that a Workflow’s batch group will be associated to a designated batch server.
  1. To view and modify the current batch server set up on an AOS or group of AOSs, go toAdministration | Setup | Server Configuration.
    Microsoft Dynamics AX 2009 Administration
  2. An AOS can be set up as a batch server and service users. However, depending on the performance and resource requirements for an implementation, it is recommended to have an AOS as a dedicated batch server.
  3. Select the appropriate AOS that should run as the batch server and then click on the General tab and ensure that the Is Batch Server checkbox is marked.
    Microsoft Dynamics AX 2009 Administration
  4. Go to the Batch server groups tab, and add the Workflow batch groups that we created.
    Microsoft Dynamics AX 2009 Administration
  5. To specify the number of batch threads/processes that can run simultaneously and the time the batch processes can run, go to the Batch server schedule tab and provide the desired values. The following batch schedule is the default schedule and runs eight threads at any time of the day:
    Microsoft Dynamics AX 2009 Administration

Configuring Workflow

Now that we have an AOS that can run Workflows in a batch server, we must configure the batch processes. This section will guide you through the process of:
  • Configuring Dynamics AX to use the Workflow service
  • Specifying Workflow parameters for notifications and general use

Running the Workflow infrastructure configuration wizard

The Workflow infrastructure configuration wizard allows you to quickly specify the Workflow web service address, Workflow batch groups, and specify when the Workflow batch jobs should run. It also validates the Workflow web service and ensures that it is accessible by the AOS. In this section, we will cover the process of running the wizard.
  1. Go to the Administration module and in the Setup section, open the Workflow infrastructure configuration wizard. Once in the Workflow infrastructure configuration wizard form, click on the Next button, as shown in the following screenshot:
    Microsoft Dynamics AX 2009 Administration
  2. In the next section of the wizard, you may specify the URL of the Workflow web service, which you created as described in Creating a website for Workflow section of this article. By default, this field will already be populated if you installed the Workflow service correctly. However, if you want to modify this field, you certainly have the option to do so. Be sure to click on the Validatebutton to confirm that the URL is accessible by Dynamics AX, as shown in the following screenshot:
    Microsoft Dynamics AX 2009 Administration
  3. In the following section of the wizard, you will be able to see which batch group is designated to execute Workflow batch jobs. Verify that the appropriate batch group is assigned and then click on the Next button.
    Microsoft Dynamics AX 2009 Administration
  4. In this section of the wizard, you can specify how many times you want the batch server to repeat the Workflow batch process. The lowest value you can enter is 1. The wizard will allow you to enter in 0; however, the batch system only accepts 1 as the lowest value. Once you have specified the appropriate value, click on the Next button.
    Microsoft Dynamics AX 2009 Administration
  5. The next and final screen of the wizard displays a summary of all the settings that were specified. Click on the Finish button to apply these new settings and to make Dynamics AX start using the Workflow service.
    Microsoft Dynamics AX 2009 Administration

Specifying Workflow settings

The Workflow infrastructure configuration wizard assists in setting up common Workflow settings that are shared between companies. However, company specific settings for Workflow must also be specified such as Number sequences. Additional settings can be customized but are not required, such as specifying custom e-mail templates or another Workflow web service URL. In this section, we will cover the process of specifying company-specific workflow settings.
  1. Go to Basic | Setup | Settings for workflow. In the General tab, provide a custom template forApproval and task notifications. By default, no template is specified. In this case, a generic e-mail template will be used.
    Microsoft Dynamics AX 2009 Administration
  2. In the Administration tab, verify that the correct Workflow web service is listed and verify that the system can access the service by clicking on the Validate button.
    Microsoft Dynamics AX 2009 Administration
  3. In the Number sequences tab, ensure that Number sequences are mapped to the appropriateReference.
    Microsoft Dynamics AX 2009 Administration
If number sequences are not mapped, it may be because the number sequence wizard never ran. To run the number sequence wizard, go to Basic | Setup | Number sequencesto load the Number sequences form. In the Number sequences form, run the wizard by clicking on the Wizard button. Dynamics AX will automatically check which number sequences need to be set up and associate number sequences to their reference.

Wednesday 14 December 2011

AxPopup Controls in EP


AxPopup controls are used to open a page in a popup browser window and upon closing a popup page, pass data from the popup page back to the parent page and trigger anOnPopupClosed server event on the parent. This functionality is encapsulated in two controls - AxPopupParentControl to be used in the parent page and AxPopupChildControl to be used on the popup page. They both derive from AxPopupBaseControl. These controls are AJAX-compatible, so they can be created conditionally as part of a partial update.
Data can be passed from the popup page back to the parent page using AxPopupFieldobjects. They are exposed via the Fields property of the AxPopupBaseControl, from which both AxPopupParentControl and AxPopupChildControl are derived.
AxPopupParentControl and AxPopupChildControl have fields with the same names. When the popup page closes, the value of each field of the AxPopupChildControl is assigned (via client-side script) to the correspondent field in the AxPopupParentControl.
AxPopupField can optionally be associated with another control, such as TextBox or any other control, by assigning its TargetId property to the ID property of the target control. This is useful, for instance, when the popup page has a TextBox control. In order to pass the user input to the parent page upon closing the popup, and to do it entirely on the client hence avoiding the round trip, a field needs to be associated with the TextBox control.
In AX 2009 this approach is used in number of places and one such control is the Business Relations list.
The AxPopupField control is placed in the user control displaying the list. In the code behind, the toolbar action calls the popup using the GetOpenPopUpEventReference method. Both the parent control and the childcontrol uses the field with the same namehiddenCustomerAccountNo to pass the values back& forth. The childcontrol gets the value from the text box using the TargetControlID.

smmBusRelListGrid.ascx

List containing the ParentControl from the popup
<dynamics:AxPopupParentControl ID="PopupConvertCustomer" runat="server"PopupHeight ="180" PopupWidth="400"  >
    <dynamics:AxPopupField name="hiddenCustomerAccountNo"  />   
</dynamics:AxPopupParentControl>

smmBusRelListGrid.ascx.cs

Code behind opening up the popup using GetOpenPopUpEventReference
protected void AddCustomerAccountNoScript(SetMenuItemPropertiesEventArgs e,string custAccount)
    {
        AxUrlMenuItem menuItem = newAxUrlMenuItem(CUSTOMER_ACCOUNT_DIALOG);
        DataSetViewRow row = this.GetCurrentDataSetViewRow();
        if (row != null)
        {
            AxTableContext context = AxTableContext.Create
            (row.GetTableDataKey(row.DataSetView.Metadata.RootDataSource,null));

            menuItem.MenuItemContext = context;

            //Adding the CustAccount QueryString variable
            if (custAccount != string.Empty)
            {
                menuItem.ExtraParams.Add("CustAccount", custAccount);
            }
            menuItem.RemoveNavigation = true;

            //Calling the javascript function to set the properties of opening the customer account
            //on clicking the menu items.
            e.MenuItem.ClientOnClickScript =this.PopupConvertCustomer.GetOpenPopupEventReference(menuItem);
        }
    }

CustomerAccountDialog.ascx

The popup form  transferring  the value entered in the target  to the parent control by using the same control name.
<div>
    <br />
    <br />
    <table style="width100%">       
        <tr>
            <td class="PopoverFormText">
                <asp:Label ID="lblCustAccount" runat="server" Text="<%$ axlabel:@SYS7149 %>"></asp:Label>                       
            </td>
            <td class="PopoverFormText" >
                <asp:TextBox ID="txtCustAccount" runat="server"MaxLength="20" ></asp:TextBox>  
                <dynamics:AxPopupChildControl ID="popupChild"runat="server">
                    <dynamics:AxPopupField name="hiddenCustomerAccountNo"TargetControlId="txtCustAccount" />
                </dynamics:AxPopupChildControl>       
            </td>                   
        </tr>
        <tr><td colspan="3"><br /> <hr class="hr" />
            </td></tr>
        <tr>
            <td align="right" colspan="2">
            <asp:Button  id = "OkButton" CssClass="okCancelButton" runat="server"  Text="<%$ axlabel:@SYS5473 %>" onclick="OkButton_Click" />
            <input id="CancelButton" class="okCancelButton" runat ="server"type="button" value="<%$ axlabel:@SYS50163 %>" onclick="window.close();" />
           
            </td>
            <td style="width10%"></td>
        </tr>
    </table>   
</div>

CustomerAccountDialog.ascx.cs

Pop up closed after validing the data entered in the popup , giving control back to the parent page.
//Used to validate the CustAccount no etered.
    protected void OkButton_Click(object sender, EventArgs e)
    {
        try
        {
            if (this.txtCustAccount.Text.Equals(string.Empty))
            {
                //Displaying error message: Account number is not specified
                DisplayInfolog(InfoType.Error, "@SYS24085");
                return;
            }

            //Validating the Customer Account no. entered
            if(!ApplicationProxy.SmmOpportunityStatusUpdate.checkCustomerAccount(this.AxSession.AxaptaAdapter,this.txtCustAccount.Text))
            {
                return;
            }

            //Calling the script for closing the dialogbox
            this.popupChild.ClosePopup(truetrue);
        }
        catch (Exception ex)
        {
            AxExceptionCategory exceptionCategory;
            // This returns true if the exception can be handled here
            if (!AxControlExceptionHandler.TryHandleException(this, ex, outexceptionCategory))
            {
                // The exception was fatal - in this case we re-throw.
                throw;
            }
        }
    }