Thursday, June 5, 2014

Read a Text File

// Read a Text File

static void ReadDateFromTxtFile(Args _args)
{
    #File
    TextIo                  io;
    container               c;
    str               itm, name;
    ;
    io = new TextIo("U:\\Test.txt", #io_read);
    if (!io)
    {
        throw error("Error reading file");
    }
    io.inFieldDelimiter(','); //This can be any delimiter, I'm just using Semicolon as an example
    io.inRecordDelimiter(#delimiterCRLF); //CRLF = Carriage Return Line Feed
    ttsbegin;
    while (io.status() == IO_Status::Ok)
    {
        c = io.read();
        if (io.status() != IO_Status::Ok)
        {
            break;
        }
        itm = conpeek(c, 1);
        name=  conpeek(c, 2);
        info(itm + '-->' + name);
    }
    ttscommit;
}

Based on the input given Number sequence will generate

//Based on the input given Number sequence will generate

static void TimeSheetNumFromQty(Args _args)
{
    TSTimesheetNbr      num;
    CustTable           custTable;
    NumTmp              tmp;
    int                 i = 1;
    NumberSeq           numberSeq;
    Dialog              dialog;
    DialogGroup         dialogGroup;
    DialogField         dialogFieldQty;
    ;
    dialog          = new   Dialog("Quantity Input");
    dialogGroup     = dialog.addGroup(" qty");
    dialogFieldQty  = dialog.addField(ExtendedTypestr(Name),"Qty :");
    numberSeq       = NumberSeq::newGetNum(ProjParameters::numRefTimesheetNbr());

    if(dialog.run())
    {
        while(i <= any2int(dialogFieldQty.value()))
        {
            num             = numberSeq.num();
            tmp.AccountNum  = "1001";
            tmp.SerialNum   = num;
            tmp.CustName    = "CBS";
            //info(num);
            //info(strFmt("%1",dialogFieldQty.value()));
            info(strFmt("%1    - %2   - %3   - %4",i,tmp.AccountNum,tmp.SerialNum,tmp.CustName));
            i++;
        }
     }
}

Friday, May 23, 2014

Job Code to Test Dp class (Process report) input from Contract Class...

// Job Code to Test Dp class from input Contract Class... Testing... And change a Temp table to Regular table while testing in job

static void DPClassTest(Args _args)
{
    //initialize contract
    CustContract cont = new    CustContract();
    CustDP        dp  = new     CustDP();
    //fill the contract
    cont.parmRecId(5637144576);
    //pass the contract
    dp.parmDataContract(cont);
    //fill the table
    dp.processReport();
}

Wednesday, May 21, 2014

Job to Create N number of companys and import the data in it.


//Job to Create N number of companys and import the data in it.

static void CreateCompanies(Args _args)
{
DataArea dataarea;
counter i;
CompanyDomainList companyDomainList;
CompanyDomainList cCompanyDomainList;
sysdataImport sysDataimport;
Application gappl = new Application();
filename filename;
;
filename = "D:\\Computer\\0";

for(i=1 ; i<301 ; i++)
{
DataArea.clear();
DataArea.Id = 'C' + int2str(i);
DataArea.name = 'Company' + int2str(i);
DataArea.insert();
xDataArea::insertPost(dataArea);

while select * from companyDomainList where companyDomainList.CompanyId == DataArea.Id
{
select firstonly cCompanyDomainList
where cCompanyDomainList.CompanyId == DataArea.Id &&
cCompanyDomainList.DomainId == companyDomainList.DomainId;

if (!cCompanyDomainList)
{
cCompanyDomainList.data(companyDomainList.data());
cCompanyDomainList.CompanyId = DataArea.Id;
cCompanyDomainList.insert();
}

//create the default company
gappl.setDefaultCompany(DataArea.Id,false);
syssecurity::reload(false);
InfoLog.navPane().loadStartupButtons();
Infolog.navPane().refreshFavorites(infolog.navPane().selectedFavoriteGroup(),xInfo::currentWorkspaceNum());

sysDataImport = new sysDataImport();
sysDataImport.parmDropCompany(true);
sysdataimport.parmDeleteTables(connull());
sysDataImport.parmSilent(true);
sysdataImport.parmFilename(filename);
sysDataImport.parmServerAccess(Noyes::Yes);
sysdataImport.run(false);
//sysDataImport::importFile("D:\\MyShare\\Data\\5.0SP1\\ExtendedData\\40ExtendedData1380.dat",FileType::Binary);
}

if(i==14 || i==25 || i==40 || i==60 || i==75 || i== 90 || i== 110 || i== 130 ||
i==150 || i==170 || i==190 || i==220 || i==240 || i==270)
infolog.clearBrowser();

}
}

AX Job to export Security Key to CSV file.

//AX Job to export Security Key to CSV file.
Error ...

static void AOTGetProperty(Args _args)
{
 #aot #properties Boolean writeFile;
Boolean infoDebug;
CommaIo outFile;
TreeNode tn = TreeNode::findNode(#SecurityKeysPath);
str securityKeysName;
str securityKeyID, Property;
int sID; str errMsg; ;
infoDebug = false;
// ***OPTION*** View InfoLog Output (true / false) writeFile = true;
// ***OPTION*** Export results to CSV file (true / false) errMsg = "";
 //"--- NOT DEFINED ---";
//C:\Users\m.a.gudidevuni\Documents outFile = new AsciiIo("C:\\GTA\\SecurityKey.CSV","W");
outFile.outFieldDelimiter("\r\n");
outFile.outRecordDelimiter("\r");
tn = tn.AOTfirstChild();
while (tn)
{
securityKeysName = findProperty(tn.AOTgetProperties(), #PropertyName);
securityKeyID = findProperty(tn.AOTgetProperties(),#PropertyId);
sID = tn.applObjectId();
if(infoDebug)
{
info(strfmt('SecurityKeysName %1 with ID : %2',securityKeysName,sID));
}
if(writeFile)
{
 outFile.write(securityKeysName + " , " + strReplace(int2str(sID),",",""));
}
// info(strfmt('SecurityKeysName %1 with ID : %2',securityKeysName,sID));
// Property = tn.AOTgetProperties();
// info(strfmt('%1', findProperty(Property, 'ID')));
// info (strfmt( // 'SecurityKeysName %1 has the ID property specified as %2', // securityKeysName, securityKeyID));
tn = tn.AOTnextSibling();
}
}

Tree node to Excel file:

Tree node to Excel file:

static void CreateExcelTreeNode(Args _args)


{



SysExcelApplication xlsApplication;

SysExcelWorkBooks xlsWorkBookCollection;

SysExcelWorkBook xlsWorkBook;

SysExcelWorkSheets xlsWorkSheetCollection;

SysExcelWorkSheet xlsWorkSheet;

SysExcelRange xlsRange;

AsciiIO tmpfile;

Filename tmpfilename;

FileIOPermission permission;

TreeNode treeNode;

TreeNode treeNodeTables;

#File

#AOT

int row = 1;

str fileName;

;



treeNodeTables = TreeNode::findNode(#SecurityKeysPath);



// Name of the Excel document.



fileName = "C:\\test.xsl";



// Excel open and initialize.



xlsApplication = SysExcelApplication::construct();

xlsApplication.visible(true); //Generate new Excel worksheet.

xlsWorkBookCollection = xlsApplication.workbooks();

xlsWorkBook = xlsWorkBookCollection.add();

xlsWorkSheetCollection = xlsWorkBook.worksheets();

xlsWorkSheet = xlsWorkSheetCollection.itemFromNum(1);

// Write headlines cells in the worksheet.

xlsWorkSheet.cells().item(row,1).value('Name'); xlsWorkSheet.cells().item(row,2).value('ID');

row++;

// first table

treeNode = treeNodeTables.AOTfirstChild();

// Excel worksheet with fill data (Excel fill-cells).

while (treeNode != null)

{

xlsWorkSheet.cells().item(row,1).value(treeNode.AOTname()); xlsWorkSheet.cells().item(row,2).value(treeNode.applObjectId());

row++; // next table

treeNode = treeNode.AOTnextSibling();

}

// Check whether the document already exists.

if(WinApi::fileExists(fileName))

{

WinApi::deleteFile(fileName);

}

// Excel document store.

xlsWorkbook.saveAs(fileName);

//Close Excel.

xlsApplication.quit(); xlsApplication.finalize();

}

Resolving Ctrl+F5 Error on creation of Item Master while edit and update in Master data in AX2012:

Resolving Ctrl+F5  Error on creation of Item Master while edit and update in Master data in AX2012:

 FormRun         formRun;
    FormObjectSet   formObjSet;
    int             i;
    InventTable     linventTable;

    // refresh and reread inventTable datasource if exists in form
    if (this.isFormDataSource())
    {
        formRun = this.dataSource().formRun();
        for (i=1; i<= formRun.dataSourceCount(); i++)
        {
            if (formRun.dataSource(i).cursor() is InventTable)
            {
                formObjSet = formRun.dataSource(i);
                linventTable = formObjSet.cursor() as InventTable;
                break;
            }
        }
        if (!linventTable)
        {
            linventTable = InventTable::find(this.ItemId, true);
        }
        if (linventTable)
        {
            if (formObjSet)
            {
                formObjSet.refresh();
                formObjSet.reread();
            }
        }
    }

AOS Server name from Job

// AOS Server name from Job
static void getServerNameForCurrentSession(Args _args)
 {
   sysClientSessions cliSessions;
   sysServerSessions svrSessions;
   ;
   select svrSessions
     exists join cliSessions
       where cliSessions.SessionId == sessionID()
         && cliSessions.ServerID == svrSessions.ServerId;
   info(substr(svrSessions.AOSId, 1, strfind(svrSessions.AOSId, '@', 1, strlen(svrSessions.AOSId))-1));
 }

Friday, May 16, 2014

Get Count of Lines from Header table record

// To Get Count of Line from Header  table

    real a,b;
    int64 cnt;

    a = RfqDisc.realValue();
    select count(RecId) from  PurchRFQCaseLine where PurchRFQCaseLine.RFQCaseId == PurchRFQCaseTable.RFQCaseId;
    cnt = PurchRFQCaseLine.RecId;
    b = a/cnt;
    while select PurchRFQCaseLine
                where PurchRFQCaseLine.RFQCaseId == PurchRFQCaseTable.RFQCaseId
    {
            PurchRFQCaseLine.LineDisc = b;
            PurchRFQCaseLine.update();

    }

    PurchRFQCaseLine_ds.reread();
    PurchRFQCaseLine_ds.research();
    PurchRFQCaseLine_ds.refresh();


Thursday, May 15, 2014

Class ID and Number get through X++

// Class ID and Number get through X++

static void classIdNUmGetExample(Args _args)
{
    int i,j;
    WorkTimeCheck w; // class
    ;
    i = classIdGet(w);
    print "Class ID for object is " + int2Str(i);
   

    j = classNum(PurchTableForm); //class name
    print "Class NUm for object is " + int2Str(j);
    print j;
    pause;
}

Skip Inventory reservation on Sales order lines in D365FO

[ExtensionOf(classStr(InventUpd_Reservation))] final class InventUpd_ReservationCls_SAN_Extension {     void updateNow()     {         if(mo...