Alfasith AX

Alfasith AX
اللَّهُمَّ انْفَعْنِي بِمَا عَلَّمْتَنِي، وَعَلِّمْنِي مَا يَنْفَعُنِي، وَزِدْنِي عِلْمًا

Sunday, September 13, 2015

Look up date and calendar in AX

Hi,

void lookup()
{
    ProjPeriodId    projPeriodId = DNGRMParameter::find().PeriodId;
    ProjPeriodTo    projPeriodTo;
    ProjControlPeriod  projControlPeriod = new ProjControlPeriod();
   // projControlPeriod = element.args().caller().runbase();
    //if (!projControlPeriod.parmPeriodic())
    //{
        //if (this.dateValue())
        //{
            //projPeriodTo = this.dateValue();
        //}
        //else
        //{
            //projPeriodTo = ProjPeriodLine::findPrevFromDate(projPeriodId, systemdateget()).PeriodTo;
        //}
    //}
    //else
    //{
        if (this.dateValue())
        {
            projPeriodTo = this.dateValue();
        }
        else
        {
            projPeriodTo = ProjPeriodLine::findPrevFromDate(projPeriodId, systemdateget()).PeriodTo;
        }
   // }

    ProjPeriodLine::lookupPeriodTo(this, projPeriodId, projPeriodTo);
}

Regards,

Code to call Number sequence in AX 2012

Hi,

// You may use in initValue of the table or datasource or for insert the records using the codes.
NumberSeq numberSeq;
numberSeq = NumberSeq::newGetNum(DpayHRM::EdtName());
print  num.num(); // instead of print you may assign to the table.

Regards,

Code to run the report in clicked method of the button in AX

Hi,

void clicked()
{
    Args            args;
    ReportRun       reportRun;
    NSGEosTransactions  esotransactions;
    ;
     select esotransactions where esotransactions.EosTransId == NSGEosTransactions.EosTransId;
    args    = new args();
    args.name(reportstr(NSG_EOSReport)); // Report name
    args.record(esotransactions); 
    args.parm(NSGEosTransactions.EosTransId); // Parameter value that I passes.
    reportRun = classFactory.reportRunClass(args);
    reportRun.init();
    reportRun.run();
}


Regards,

Any currency to accounting currency in AX 2012

Hi,

Currency::amount(markupTransAllocate.Value, markupTransAllocate.CurrencyCode);

Regards,

Thursday, August 20, 2015

X++ code to validate & post invent Journal in AX 2012

Hi,

static void AlfasithPostJournal(Args _args)
{ 
    InventJournalCheckPost      inventJournalCheckPost;
    InventJournalTable          inventJournalTable;
    ; 
    inventJournalTable = InventJournalTable::find("INV-0001245");
    inventJournalCheckPost = InventJournalCheckPost::newJournalCheckPost(JournalCheckPostType::Check, inventJournalTable);
    inventJournalCheckPost.parmThrowCheckFailed(true);
 // This true enable to prompt the error msg validate the journal
    try
    { 
        inventJournalCheckPost.run();
    }
    catch
    {
        info("The journal contains errors.");
    }
}
*************************************OR****************************************
static void AlfasithPostJournal(Args _args)
{ 
    InventJournalCheckPost      inventJournalCheckPost;
    InventJournalTable          journalTable;
    ; 
    journalTable= InventJournalTable::find("INV-0001245");
if(InventJournalCheckPost::newPostJournal(journalTable).validate()) InventJournalCheckPost::newPostJournal(journalTable).run();   
}

Regards,

Thursday, August 13, 2015

Creating a views in AX

Hi,

Create views 

  • Create new view
  • Metadata node, right-click on the Data Sources node and select new data source.
  • Change table property to the table name (parent).
  • In the ds of parent table create another ds and select table property as child table.
  • In the child table ds select yes to relation property.
  • Observe If you expand the Relations node you will find auto populated relation.

Regards,

Dynamic query by linking 2 tables in AX

Hi,

Query by linking two tables

static void queryEmpDept(Args _args)

{
Query query;
QueryBuildDataSource queryBuildDataSource1,queryBuildDataSource2;
QueryBuildRange queryBuildRange;
QueryBuildLink queryBuildLink;
QueryRun queryRun;
DeptTrainingTable deptTrainingTable;
EmpTrainingTable empTrainingTable;
;
// Create a new query object
query = new Query();
// Add the first data source to the query
queryBuildDataSource1 = query.addDataSource(tablenum(DeptTrainingTable));
// Add the range to this first data source
queryBuildRange = queryBuildDataSource1.addRange(fieldnum(DeptTrainingTable, DeptId));
// Set the range
queryBuildRange.value("ID002");
// Add the second datasource to the first data source
queryBuildDataSource2 =queryBuildDataSource1.addDataSource(tablenum(EmpTrainingTable));
// Add the link from the child data source to the parent data
//source
queryBuildLink = queryBuildDataSource2.addLink(fieldnum(DeptTrainingTable,DeptId),fieldnum(EmpTrainingTable, DeptId));
// Create a new QueryRun object based on the query definition
queryRun = new QueryRun(query);
// Loop through all the records returned by the query
while (queryRun.next())
{
// Get the table data by using the get() method
deptTrainingTable = queryRun.get(tablenum(DeptTrainingTable));
empTrainingTable = queryRun.get(tablenum(EmpTrainingTable));
info (strfmt("Dept Id %1, Dept Name %2, Employee Id %3, Employee Name %4 ", deptTrainingTable.DeptId,deptTrainingTable.DeptName,empTrainingTable.EmpTrainingId,empTrainingTable.Name));
}
}

Regards,


Write a text file in AX

Hi,

static server void WriteTextFile(Args _args){TextIo file;// Using the @ before the filename// enables us to use single path// delimiters. If you don't use it// you will have to write the path like this:// "c:\\temp\\cars.txt"FileName filename = @"C\Desktop\Reports.txt"; //Here give your location where to saveEmpTrainingTable empTrainingTable;container con;
FileIoPermission permission;#File;try{    // Create the permission classpermission = new FileIoPermission(filename, #io_write);// Add a request for permission before new TextIo()permission.assert();// Create the TextIo objectfile = new TextIo(filename, #io_write);if (!file)
throw Exception::Error;
// Specify the delimitersfile.outRecordDelimiter(#delimiterCRLF);file.outFieldDelimiter(";");// Loop through the data sourcewhile select empTrainingTable
{// Empty the containercon = connull();// Set the data into the containercon = conins(con, 1, empTrainingTable.DeptId);con = conins(con, 2, empTrainingTable.EmpTrainingId);con = conins(con, 3, empTrainingTable.Name);con = conins(con, 4, empTrainingTable.Phone);con = conins(con, 5, empTrainingTable.Date);// Write the container to the filefile.writeExp(con);}}catch(Exception::Error)
{error("You do not have access to write the file to the selected folder");}// Revert the access privilegesCodeAccessPermission::revertAssert();}

Regards,

Sunday, August 9, 2015

Update sales order line amount through X++

Hi,

Static void AlfasithUpdateSalesId(Args _args)
{
SalesLine  salesLine;
;
ttsbegin;
while select forupdate salesline where salesline.salesid == 'SO-00215'
{
salesline.calcLineAmount();
salesline.update();
}
info(strfmt("1% Sales id - sales amount was updated",salesline.salesid ));
}

Regards,

DMF Issue - "Could not load file or assemble.The system cannot find the file specified"

Hi,

DMF Issue - "Could not load file or assemble.The system cannot find the file specified".


There are list objects and files should be available in certain folders on installing the DMF.

A. Installation procedure.

1. Data Import / Export Framework (DIXF) service should be installed on a SQL Server machine.
2. AOS component should be installed on AOS server machine.
3. Client can be installed any machine.

B. Verify the existence of files and objects in the directory.

1. AOS server:
Dir: 'C:\Program Files\Microsoft Dynamics AX\60\'

Microsoft.Dynamics.AX.Framework.Tools.DMF.DriverHelper
Microsoft.Dynamics.AX.Framework.Tools.DMF.SSISHelper
Microsoft.Dynamics.AX.Framework.Tools.DMF.SSISHelperService
Microsoft.Dynamics.AX.Framework.Tools.DMF.SSISHelperService.exe

2. Client system.
Dir: 'C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin\'

Microsoft.Dynamics.AX.Framework.Tools.DMF.DriverHelper.dll
Microsoft.Dynamics.AX.Framework.Tools.DMF.Mapper.dll
Microsoft.Dynamics.AX.Framework.Tools.DMF.PreviewGrid.dll
Microsoft.Dynamics.AX.Framework.Tools.DMF.ServiceProxy.dll

C. Add the users in to Microsoft Dynamics AX Data Import Export Framework Service Users. 
D. Activate the DMF inbound services in AX client.
E. Restart the AOS.

Regards,

X++ code to delete the employee

Hi,

static void AlfasithDeleteAnEmpl(Args _args)
{
    HcmWorker hcmWorker,hcmWorkerSel;
    HcmEmployment  hcmEmployment,hcmEmploymentSel;
    DirPartyTable  dirPartyTable,dirPartyTableSel;
    DirPerson      dirPerson,dirPersonSel;
    DirPersonName  dirPersonName,dirPersonNameSel;
    DirAddressBookParty  dirAddressBookParty,dirAddressBookPartySel ;
        int n=0;
    ;

     select hcmWorker where  hcmWorker.PersonnelNumber == "000097";
    // If you dont select particular personnel number you can delete complete employees..
    select HcmEmployment where hcmEmployment.Worker == hcmWorker.RecId;
    select dirPerson where dirPerson.RecId ==hcmWorker.Person;
    select dirPartyTable where dirPartyTable.RecId == dirPerson.RecId;
    // deleting the selected records as follows...
    delete_from dirAddressBookParty where dirAddressBookParty.Party == dirPartyTable.RecId;
    delete_from dirPersonNameSel where dirPersonNameSel.RecId == dirPerson.RecId;
    delete_from dirPartyTableSel where dirPartyTableSel.RecId == dirPartyTable.RecId;
    delete_from HcmEmploymentSel where HcmEmploymentSel.RecId == HcmEmployment.RecId;
    delete_from dirPersonSel where dirPersonSel.RecId == dirPerson.RecId;
    delete_from hcmWorkerSel where hcmWorkerSel.RecId == hcmWorker.RecId ;
    n++; // Here I'm Alfasith made n++ for printing the no of deletion in records...
    print n;
    pause;
}

Regards,

Release the product using X++

Hi,

static void AlfasithReleaseProducts(Args _args)
{
EcoResProductReleaseManagerBase::releaseProduct(
                EcoResProduct::findByProductNumber('1022214').recId,
           CompanyInfo::findDataArea('CEU').RecId);
    info("Product released");
    // here Product name and item name & Product ID and Item Id will be same...
}

Regards,

DMF issue - Access denied for the user - On clicking preview data

Hi,

DMF issue -"Access denied for the user" on-clicking preview data in after validating.


1.This error will be retained even you add the user into Microsoft Dynamics AX Data Import Export Framework Service Users .
 For that we need to update the server (Windows updates ) and restart the server.  This will solve your issue.

Regards,

DMF issue - Access denied for the user

Hi,

"Access denied for the user".

This error will be prompted in many cases.
This is post will solution for the prompt during the validation of shared folder and my next post will be explain to preview records after validating.

1. Make sure that concern folder granted with full rights to everyone.
2. in shared working directory needs to mentioned as "\\serverName\FolderName\"  not as Drive:\Folder\ 
3.Add the DMF user in to local user group of Microsoft Dynamics AX Data Import Export Framework Service Users.
4. Restart the AOS.

Regards,


FileNameSplit() to slip the Directory, file name and extension in D365 FnO

 Hi,     /// <summary>     /// Validate the Fileformat     /// </summary>     /// <param name = "filepath">FileP...