Friday, 23 February 2018

Export data from AX to XML file

Class Declaration:

class CustomerExportXML
{
}

Main Method:

public static void main(Args _args)
{
    XmlDocument   doc;
    XmlElement      nodexml;
    XmlElement      nodeTable;
    XmlElement      nodeAccountNum;
    XmlElement      nodeCustGroupId;
    XmlElement      nodeName;
    CustTable          custTable;
    DirPartyTable   dirPartyTable;
    DirParty            dirParty;
    MethodInfo       methodInfo;
    #define.filename(@'D:\Temp\TestXML.xml')

    doc     = XmlDocument::newBlank();
    nodexml = doc.createElement('xml');
    doc.appendChild(nodexml);

    while select party, AccountNum, CustGroup from custTable join dirPartyTable
        //where custTable.party == DirPartyTable.RecId
    {
        nodeTable = doc.createElement(tableStr(CustTable));
        nodeTable.setAttribute(fieldStr(CustTable, RecId),int642str(custTable.RecId));
        nodexml.appendChild(nodeTable);

        nodeAccountNum = doc.createElement(fieldStr(CustTable, AccountNum));
        nodeAccountNum.appendChild(doc.createTextNode(custTable.AccountNum));
        nodeTable.appendChild(nodeAccountNum);

        nodeCustGroupId = doc.createElement(fieldStr(CustTable, CustGroup));
        nodeCustGroupId.appendChild(doc.createTextNode(custTable.CustGroup));
        nodeTable.appendChild(nodeCustGroupId);

        Commented Line Starts
        //nodeName = doc.createElement(fieldStr(dirPartyTable, Name));
        //nodeName.appendChild(doc.createTextNode(custTable.name()));
        //nodeTable.appendChild(nodeName);
        Commented Line Ends

        nodeName = doc.createElement("Name");
        nodeName.appendChild(doc.createTextNode(CustTable.name()));
        nodeTable.appendChild(nodeName);
    }
    doc.save(#filename);
    info(strFmt("File %1 created.", #filename));
}

Thursday, 15 February 2018

Creating a applicant through job X++

static void CreateAplicant(Args _args)
{
    HcmApplicant    hcmApplicant;
    DirPerson       dirperson;
    DirPersonName   dirPersonName;
    NumberSeq       sequence;
    HcmApplicantId  applicantId;
    RecId           person,   dirPersonRecid;
    DirPartyRecId   partyRecId;
    Name            personName;

    personName = "Krishna" +" " +"kumar"+ " " + "test";
    partyRecId = DirPartyTable::createNew( DirPartyType::Person, personName).RecId;

    dirPersonRecId = DirPerson::find(partyRecId).RecId;

    dirPersonName.FirstName = "Krishna";
    dirPersonName.MiddleName = "kumar";
    dirPersonName.LastName = "test";
    dirPersonName.Person = dirPersonRecId;

    if (dirPersonName.validateWrite())
    {
        dirPersonName.insert();
    }
    ttsbegin;   
    applicantId = NumberSeq::newGetNum( HRMParameters::numRefApplicantId()).num();
    ttscommit;
    hcmApplicant.ApplicantId = applicantId;

    if(dirPersonRecId != hcmApplicant.Person)
    {
        hcmApplicant.Person = dirPersonRecId;
        hcmApplicant.insert();
    }
}

Tuesday, 20 June 2017

Import the data from Excel to D365/Ax7

using System.IO;
using OfficeOpenXml;
using OfficeOpenXml.ExcelPackage;
using OfficeOpenXml.ExcelRange;

class RunnableClass1
{      
    /// <summary>
    /// Runs the class with the specified arguments.
    /// </summary>
    /// <param name = "_args">The specified arguments.</param>
    public static void main(Args _args)
    {  
        System.IO.Stream            stream;
        ExcelSpreadsheetName        sheeet;
        FileUploadBuild             fileUpload;
        DialogGroup                 dlgUploadGroup;
        FileUploadBuild             fileUploadBuild;
        FormBuildControl            formBuildControl;
        TableTest                          test;
        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;
                    //rowCount = 1;
                    //i=Range.Rows;

                    for (i = 2; i<= rowCount; i++)

                    {

                        test.AccountNum = range.get_Item(i, 1).value;

                        test.AccountName = range.get_Item(i, 2).value;
                        test.insert();

                    }

                }

            }

            else

            {

                error("Error ");

            }
            info("Done");

        }

       

    }

}

Friday, 16 June 2017

Design Permissions for Fields in a Table

You can use the AOT to design permissions for the fields in a table. By changing the EffectiveAccess property in permissions for each of the fields you can control the application user access to those fields. For example, you can control whether the application user can view or edit some of the fields on a form based on the security role assigned to the application user.

Prerequisites

To understand this walkthrough topic, you first need to understand the following areas:

Preliminary Environment

This topic assumes that several AOT items already exist, or that you can imagine them. The items are as follows:
  • Table – Person table, with fields CityName, and Zip.
  • Form – FieldsForm form.
  • Data source – Person table as the data source for FieldsForm form.
  • Menu – Home > Common menu, which might already exist.
  • Menu Item – FieldsMenuItem menu item, with its ObjectType property set to Form, and its Object property set to FieldsForm.
  • Security > Privilege – TestFieldPrivilege privilege.
  • Privilege > TestFieldPrivilege > Entry Point – FieldsMenuItem, with its ObjectType property set to MenuItemDisplay.
    You can test with different values for the AccessLevel property, but start with Update.
The following image displays a project that contains almost everything in the preceding list. In the next section you create the node AOT > Security > Privileges > Permissions > Tables > Person, and the field nodes under it.
AOTSecurityFieldsPermProject
The project that you create

Create Field Permissions

You can create field permissions for TestFieldPrivilege by following these steps:

  1. Add the Person table to the TestFieldPrivilege privilege. Do this by dragging the node
     AOT > Data Dictionary > Tables > Person
    onto the node at
     AOT > Security > Privileges > TestFormPrivilege > Permissions > Tables.
    TipTip
    Drag operations are easier when you have two AOT windows open. You can drag from one AOT to the other.
  2. On the new Person node, set the EffectiveAccess property to Update.
  3. At Data Dictionary > Tables > Person > Fields, highlight all fields and drag them onto the TestFieldPrivilege > Permissions > Tables > Person node.
  4. Set the EffectiveAccess property for each new field node as follows:
    • City – Update
    • Name – Read
    • Zip – NoAccess

Tuesday, 30 May 2017

SSRS Report AX 2012 - The operation has timed out error message when you run a report in Microsoft Dynamics AX

About this problem, read below and test to find if this will have improved SSRS Report performance:

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 these pre-processing way ( Similar Sales confirmation, Sales Invoice, etc. reports ), see this example below for the Dimension Statement 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 “LedgerDimensionTransStatement”.

3.    Find this menu item in AOT > Menu Items > Output

…and look at the properties, make a note of the “LinkedPermissionObject”, in this case “LedgerTransStatement”

4.    Next in the AOT > SSRS Reports > Reports, locate LedgerTransStatement, then expand this out until you see the Server Methods. Make a note of the Server Method class, in this case “LedgerTransStatementDP”

5.    In the AOT > Classes, locate and open class LedgerTransStatementDP.

6.    In the LedgerTransStatementDP\classDeclaration, change line 9 to extend SrsReportDataProviderPreProcess instead of SrsReportDataProviderBase

7.    Make a note of the Temp table used in the report, as above this is LedgerTransStatementTmp.

8.    Next, change the method LedgerTransStatementDP\processReport to add the following line after the contract (line 27):



ledgerTransStatementTmp.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 LedgerTransStatementTmp. Change the table properties as follows:



·         TableType = Regular

·         CreatedBy = Yes

·         CreatedTransactionId = Yes



10. Opened LedgerTransStatement.Detail report in Visual Studio and refreshed the data source to include new field (CreatedTransactionId).

11. Deployed the new LedgerTransStatement.Detail report.

12. In AX, did a Generate Incremental CIL.

13. Restart SSRS


Also, at this link

Microsoft Dynamics AX 2012 Reporting: How to run reports that executes longer than 10 minutes

The operation has timed out" error message when you run a report in Microsoft Dynamics AX 2012

AX 2012: Report timeout error

How To: Addressing SSRS Session Timeouts

you can find useful information about modify the SQL Reporting Send Timeout Parameter.

http://sinedax.blogspot.in/2012/11/ssrs-report-ax-2012-operation-has-timed.html

Sunday, 7 May 2017

Inserting Space between the characters in a String in Ax


Hi,

Today I would like to share you x++ code to insert space between the characters in a string in AX.

Example 1:

static void insertSpaceBtwString(Args _args)

{

str s,s1;

int i,j;

s="KORCOMPTENZ";

j= strLen(s);

for(i=1;i<=j;i++)

{

   s1=s1+subStr(s,i,1);

  if(i!=strLen(s))

  s1=s1+ " ";

}

info(s1);

}

Output:
Example 2:
Inserting space after each four digit Number

static void InsertSpace(Args _args)

{

str s,s1;

int i,j;

s="1245678945612355";

j= strLen(s);

for(i=1;i<=j;i=i+4)

{

    s1=s1+subStr(s,i,4);

    if(i+4<=j)

    s1=s1+" ";

}

info(s1);

}

Output:

Happy Daxing....

Tuesday, 4 April 2017

Publishing AX Reports – User or group name not recognized

You may encounter an issue with trying to release reports to your AX environment when you move databases between environments. The error you might receive, during the report release, is Publish_AXReport: The user or group name ‘xxx’ is not recognized


Even though everything is setup correctly in your AX environment, the error is caused by having additional records in the table SysServerSessions. If from SQL you review the data in this table you should notice that you have records that point to old servers/instances. You need to delete all the records that are not relevant to your current environment. Once done you should be able to deploy reports with getting the user or group name error.