Tuesday, April 26, 2011

Hapus semua transaksi AX

Hati-hati menggunakan script ini, semua transaksi akan terhapus (hapus per Company).
Lamanya proses tergantung jumlah data. 

static void Delete_All_Trans(Args _args)
{

    SysDatabaseTransDelete databaseTransDelete = SysDatabaseTransDelete::construct();
    ;

    if (Box::yesNo(strfmt("@SYS82778", curext()),DialogButton::No))
    {
        databaseTransDelete.run();
        info("@SYS9265");
    }


}

Hapus Customer di AX 2009 menggunakan Class AIF

static void Services_CustTable_Delete(Args _args)

{
AifEntityKeyList entityKeyList;
AifEntityKey aifEntityKey;


// Data object of Service class

CustCustomerService custService;
CustTable custTable;
;

aifEntityKey = new AifEntityKey();

entityKeyList = new AifEntityKeyList();
custService = CustCustomerService::construct();

select firstonly custTable

where custTable.Name == "Cust_Service";

aifEntityKey.parmKeyDataMap(SysDictTable::getKeyData(custTable));

entityKeyList.addEntityKey(aifEntityKey);

try

{
  // Delete Customer
  custService.delete(entityKeyList);
  info ("CustTable record was successfully deleted.");
}

catch(Exception::Error)
{
   exceptionTextFallThrough();
}


}

Buat Vendor di AX 2009 menggunakan Class AIF

Berikut Script AX 2009 untuk buat vendor baru. Penamaannya agak beda dengan customer ternyata....

static void Services_VendTable_Create(Args _args)
{
    // vendor Service class
    VendVendTableService  vendService;
    VendVendTable         vendor;

    // Data object of Service class
    VendVendTable_VendTable vendTable;
    AifEntityKeyList        entityKeyList;
    AccountNum              accountNum;
    ;

    //Service instance
    vendService =  VendVendTableService::construct();
    vendor = new VendVendTable();
    vendor.createVendTable();

    vendTable = vendor.parmVendTable().addNew();


    vendTable.parmAccountNum("001");
    vendTable.parmName("Vend_Service");
    vendTable.parmVendGroup("LAIN-LAIN");
    vendTable.parmCurrency("IDR");

    vendTable.parmPartyType(DirPartyType::Organization);

    // Create vendor
    entityKeyList = vendService.create(vendor);

    if(entityKeyList)
        accountNum = entityKeyList.getEntityKey(1).parmKeyDataMap().lookup(fieldnum(VendTable, AccountNum));
        infolog.messageWin().addLine(accountNum);

}

Buat Customer di AX 2009 menggunakan Class AIF

Berikut script untuk membuat Customer di AX 2009, dengan memanfaatkan Class AIF.
AIF nya tidak perlu di setting apapun.




static void Services_CustTable_Create(Args _args)
{
    // Customer Service class
    CustCustomerService     custService;
    CustCustomer            customer;

    // Data object of Service class
    CustCustomer_CustTable  custTable;
    AifEntityKeyList        entityKeyList;
    AccountNum              accountNum;
    ;

    //Service instance
    custService =  CustCustomerService::construct();
    customer = new CustCustomer();
    customer.createCustTable();
    custTable = customer.parmCustTable().addNew();

    custTable.parmAccountNum("001");
    custTable.parmName("Cust_Service");
    custTable.parmCustGroup("KARY STAFF");
    custTable.parmCurrency("IDR");
    //custTable.parmPartyType(DirPartyType::Organization);
    custTable.parmPartyType(DirPartyType::Person);

    // Create Customer
    entityKeyList = custService.create(customer);

    if(entityKeyList)
        accountNum = entityKeyList.getEntityKey(1).parmKeyDataMap().lookup(fieldnum(CustTable, AccountNum));
        infolog.messageWin().addLine(accountNum);

}