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();
    }
}