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");

        }

       

    }

}