Monday, 19 March 2018

Get Email for Customer / Vendor (with specific roles)

To get an email address for a customer or vendor, you can use the following statement


static void Cust_emailStmtjob(Args _args)
{
    CustTable                                        cust; //Replace with vendTable for Vendors
    DirPartyLocation                                        dirPartyLocation;
    LogisticsElectronicAddress            elecAddress;
    LogisticsElectronicAddressRole    elecAddressRole;
    LogisticsLocationRole                    locRole;
   
    select firstOnly cust
        where cust.AccountNum == '‪‪‪us-001';
    while select DirPartyLocation
        where dirPartyLocation.party == cust.Party
    {
        while select elecAddress
            where elecAddress.Location == dirPartyLocation.Location
                   && elecAddress.Type == LogisticsElectronicAddressMethodType::Email
        {
            while select elecAddressRole
                where elecAddressRole.ElectronicAddress == elecAddress.RecId
                    join locRole
                        where locRole.RecId == elecAddressRole.LocationRole
                            && locRole.Name == "Invoice"
            {
                info(strFmt("%1 - %2", elecAddress.Locator, locRole.Name));
            }
        }
    }

}

Add field on Purchase order confirmation report



Add field on Purchase order confirmation report

There is requirement to add field on PO lines and same for the confirmation report. It’s not the straight away to add field on the report. It requires to add field on other objects (table/view/query).

On PurchPurchaseOrderreport it uses the PurchLineALLVersionsview to get the details of the PO on the PurchPurchaseOrderDP. So follow the below steps to add field on PurchLineAllVersions view.



  1. Add field on the PurchLine Table
  2.  Add field on the PurchLineHistory Table
  3. Now, Refresh or Restore the queries used for PurchLineArchivedVersions and PurchLineNotArchivedVersions as this have dynamics field property to “Yes” our new fields should be added automatically on this queries and Verify the field is added on the query.
  4. Now, Restore the views PurchLineArchivedVersions and  PurchLineNotArchivedVersions( if you want add field on the views)
  5. Add field on PurchLineAllVersion, here you have to add field manually as the dynamics field property is set.
  6. That’s it, now use the field on the PurchPurchaseOrderDP to have on report. You also have to add field on tmp table.

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