Thursday, March 7, 2013

use code to control Table field: allowEdit = Yes / No

when Person name order = manual, can edit the name,

when Person Name order = (other), can't edit.



1. copy the field name from design.
        example Design-> Tab -> Tab page-> Grid ->field  AvPatient_TestSJ_Name

2. set the field auto decraration = yes from design properties

3. use it to code:


if(AvPatient_TestSJ.PersonNameOrder == AvDirPersonNameOrder_TestSJ::Manual)
        AvPatient_TestSJ_Name.allowEdit(true);

    else

        AvPatient_TestSJ_Name.allowEdit(false);


Extral knowledge* if write in method modified, have to write again in method active.





Thursday, December 20, 2012


qbds.addRange(fieldnum(AvVendorRoleTable, avRoleType)).value(strfmt("(AvRoleType == %1) || (AvRoleType == %2)", enum2int(avRoleType::Agency), enum2int(avRoleType::Pelesen)));
   
not allow edit at form searching page:
  qbds.addRange(fieldnum(AvVendorRoleTable, avRoleType)).status(1);

Wednesday, December 5, 2012

Combine Date and Time


static void AvBry_DateTime(Args _args)
{
    utcDatetime _dt1, _dt2;
    ;

    _dt1 = DateTimeUtil::newDateTime(today(), timenow());
   
    _dt2 = DateTimeUtil::newDateTime(today() - 1, timenow());
   
    if (_dt1 < _dt2)
        info("dt1 < dt2");
    else
        info("dt1 > dt2");
}

Wednesday, November 28, 2012

Reading an Excel file


1. In the AOT, create a new job named ReadExcelFile with the following code
(replace the file name with your own):

static void ReadExcelFile (Args _args)
{
    SysExcelApplication excel;
    SysExcelWorkbooks workbooks;
    SysExcelWorkbook workbook;
    SysExcelWorksheets worksheets;
    SysExcelWorksheet worksheet;

    SysExcelCells cells;
    COMVariantType type;
    int row;
    CustAccount account;
    CustName name;
    #define.filename(@'C:\temp\customers.xlsx')
    excel = SysExcelApplication::construct();
    workbooks = excel.workbooks();
    try
    {
        workbooks.open(#filename);
    }
    catch (Exception::Error)
    {
        throw error("File cannot be opened");
    }
    workbook = workbooks.item(1);
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1);
    cells = worksheet.cells();
    type = cells.item(row+1, 1).value().variantType();
    while (type != COMVariantType::VT_EMPTY)
    {
        row++;
        account = cells.item(row, 1).value().bStr();
        name = cells.item(row, 2).value().bStr();
        info(strFmt('%1 - %2', account, name));
        type = cells.item(row+1, 1).value().variantType();
    }
    excel.quit();
}
   

2. Run the job to display the contents of the file in the Infolog, as shown in the
following screenshot:




Creating an Excel file


1. In the AOT, create a new job named CreateExcelFile with the following code:

static void CreateExcelFile(Args _args)
{
    CustTable custTable;
    SysExcelApplication excel;
    SysExcelWorkbooks workbooks;
    SysExcelWorkbook workbook;
    SysExcelWorksheets worksheets;
    SysExcelWorksheet worksheet;
    SysExcelCells cells;
    SysExcelCell cell;
    int row;
    excel = SysExcelApplication::construct();
    workbooks = excel.workbooks();
    workbook = workbooks.add();
    worksheets = workbook.worksheets();
    worksheet = worksheets.itemFromNum(1);
    cells = worksheet.cells();

    cells.range('A:A').numberFormat('@');
    while select custTable
    {
        row++;
        cell = cells.item(row, 1);
        cell.value(custTable.AccountNum);
        cell = cells.item(row, 2);
        cell.value(custTable.name());
    }
    excel.visible(true);
}

2. Run the job and check the list of customers on the screen:


3. Save the list as a file for further use in the next recipe, say C:\temp\customers.xlsx.

Tuesday, November 27, 2012

Processing a project journal


1. In the AOT, create a new job named ProjJournalCreate with the following code:

static void ProjJournalCreate(Args _args)
{
    ProjJournalTable jourTable;
    ProjJournalTrans jourTrans;
    ProjJournalTableData jourTableData;
    ProjJournalTransData jourTransData;
    ProjJournalStatic jourStatic;
    ttsBegin;
    jourTableData = JournalTableData::newTable(jourTable);
    jourTable.JournalId = jourTableData.nextJournalId();
    jourTable.JournalType = ProjJournalType::Hour;
    jourTable.JournalNameId = 'Hours';
    jourTableData.initFromJournalName(ProjJournalName::find(jourTable.JournalNameId)); 
    jourStatic = jourTableData.journalStatic();
    jourTransData = jourStatic.newJournalTransData(jourTrans, jourTableData);
    jourTransData.initFromJournalTable();
    jourTrans.initValue();
    jourTrans.ProjId = '10001';
    jourTrans.initFromProjTable(ProjTable::find(jourTrans.ProjId));

    jourTrans.TransDate = systemDateGet();
    jourTrans.ProjTransDate = jourTrans.TransDate;
    jourTrans.CategoryId = 'Design';
    jourTrans.setHourCostPrice();
    jourTrans.setHourSalesPrice();
    jourTrans.TaxItemGroupId = ProjCategory::find(jourTrans.CategoryId).TaxItemGroupId;
    jourTrans.Worker = HcmWorker::findByPersonnelNumber('000062').RecId;
    jourTrans.Txt = 'Design documentation';
    jourTrans.Qty = 8;
    jourTransData.create();
    jourTable.insert();
    ttsCommit;
    info(strFmt("Journal '%1' has been created", jourTable.JournalId));
}

2. Run the job and check the results by going to Project management and accounting | Journals | Hour:


3. Click on the Lines button to open the journal lines, and notice the newly created record:




Posting a general journal


1. Open General ledger | Journals | General journal, and find previously created
journal or manually create a new one. Note the journal's number.

2. In the AOT, create a new job named LedgerJournalPost with the following code
(replace the text 000420_010 with the journal's number from the previous step):

static void LedgerJournalPost(Args _args)
{
    LedgerJournalCheckPost jourPost;
    LedgerJournalTable jourTable;
    jourTable = LedgerJournalTable::find('000420_010');
    jourPost = LedgerJournalCheckPost::newLedgerJournalTable( jourTable, NoYes::Yes);
    jourPost.run();
}
3. Run the job, and notice the Infolog, confirming that the journal was
successfully posted:



4. Open General ledger | Journals | General journal and locate the journal to make
sure that it was posted: