Tuesday, 13 May 2014

Adding FileNameOpen Extended Data Type to a Form


After add EDT FileNameOpen to form using New -> stringEdit, 


add some form methods:

str fileNameLookupFilename()
{
    return '';
}

str fileNameLookupTitle()
{
    return "@SYS53008";
}

str fileNameLookupInitialPath()
{
    return '';
}
container fileNameLookupFilter()
{
    return ['All files','*.*'];
}

After get the file path, call insert method:

public void AvInsertAttachment(filename file, int i)
{    
    DocuRef docuRef;
    DocuActionArchive archive;
    ;           
    
    if(file)
    {
        ttsbegin;
        docuRef.clear();
        docuRef.RefRecId = DirPartyEntity.RecId;
        docuRef.RefTableId = tableNum(CustTable);
        docuRef.RefCompanyId = DirPartyEntity.dataAreaId;
        docuRef.Name = strFmt("Consultant Attachment %1", i);
        docuRef.TypeId = 'File';
        docuRef.insert();
        archive = new DocuActionArchive();
        archive.add(docuRef, file);
        ttsCommit;
    }
}
Result:

Queries in AX 2012

EXPANDED QUERY IN THE AOT

Query query;
QueryRun queryRun;
QueryBuildDataSource qbds;
QueryBuildRange qbr;
SalesTable SalesTable;
;
query = new Query();
//this line attaches a table to the qbds data source object
qbds = query.addDataSource(TableNum (SalesTable));

//this line attaches a range to the 'SalesTable' 
//data source, the range is the CustAccount
qbr = qbds.addRange(FieldNum (SalesTable,CustAccount));

// The range is set to '2001'
qbr.value ('2001');

// The query will sort by sales id
qbds.addSortField (FieldNum(SalesTable,SalesId));

// The queryRun object is instantiated using the query
queryRun = new QueryRun(query);

// The queryRun object loops through all records returned
while (queryRun.next())

{
// The current record is assigned to the salesTable variable
SalesTable = queryRun.get(tableNum(SalesTable));
print SalesTable.SalesId;
}

Data Manipulation - Insert, Update, Delete



// INSERT

custTable custTable;
;
custTable.accountNum ="1234";
custTable.name ="John Customer";
custTable.insert();
_________________________________________________________________________________

//UPDATE

SalesTable salesTable;
;
ttsbegin;
while select forupdate salesTable
where salesTable.CustAccount =="2001"
{
salesTable.SalesName ="New Enterprises";
salesTable.update();
}
ttscommit;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -


InventTable InventTable;
;
ttsbegin;
while select forupdate InventTable
where InventTable.ItemGroupId =="Television"
{
InventTable.ItemPriceToleranceGroupId ="2%";
InventTable.update();
}
ttscommit;
Microsoft

_________________________________________________________________________________

//DELETE

CustTable custTable;
;
ttsbegin;
Select forUpdate custTable
where custTable.accountnum =="2032";
custTable.delete();
ttscommit;

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
//DELETE_from

CustTable custTable;
;
delete_from custTable
where custTable.AccountNum =="4018";

While Select



CustTable custTable;
while select accountNum, name, address from custTable
{
print custTable.AccountNum, " ", custTable.Name, " ",
custTable.Address;
pause;
}
_________________________________________________________________________________

CustTable custTable;
;
while select custTable
where custTable.AccountNum > "4005"
&& custTable.AccountNum < "4017"
{
print custTable.AccountNum , " ",custTable.Name;
}
pause;
_________________________________________________________________________________
//Sorting Obtion index

CustTable custTable;
;
while select custTable index AccountIdx
{
print custTable.AccountNum, " ", custTable.Name;
}
pause;

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 //ORDER BY


CustTable custTable;
;
while select custTable order by AccountNum desc
{
print custTable.AccountNum, " ", custTable.Name;
}
pause;
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

//GROUP BY
SalesTable salesTable;
;
while select count(salesid) from salesTable group by
CustGroup
{
print salesTable.CustGroup," ",salesTable.salesid;
}
pause;

_________________________________________________________________________________
//Aggregate
sum -->Returns the sum of the values in a field.
avg -->Returns the average of the values in a field.
maxof -->Returns the maximum of the values in a field.
minof -->Returns the minimum of the values in a field.
count -->Returns the number of records that satisfy the statement. Count can only be used on numerical fields, since the result will be returned in that field.



select sum(amountMST) from ledgerTrans;
sumAmountMST = ledgerTrans.amountMST;
select count(recId) from ledgerTrans;
countLedgerTrans = ledgerTrans.recId;






Look up







// create in Form/Fields/fields name/Methods
public void lookup(FormControl _formControl, str _filterStr)
{

    ;
    lookupMaster::lookupMasterNumber(_formControl);
}




//Create in class/ new method
public static boolean lookupMasterNumber(FormStringControl   _ctrl)

{
    SysTableLookup          sysTableLookup = SysTableLookup::newParameters(tablenum(Master1), _ctrl);
    Query                   query;
    QueryBuildDataSource    qdbsTransport;
    AvVendorRoleTable       avVendorRoleTable;
 
    ;
    //display
    sysTableLookup.addLookupfield(fieldnum(Master1, MasterNumber), true);
    sysTableLookup.addLookupfield(fieldnum(Master1, MasterID));

    //logic and assign table & field
    query           = new Query();
    qdbsTransport   = query.addDataSource(tablenum(Master1));
    qdbsTransport.addRange(fieldnum(Master1, AvStatus)).value(queryValue(Avstatus::Approve));
 

    sysTableLookup.parmQuery(query);
    sysTableLookup.performFormLookup();
    return true;
}

Dialog Boxes

Dialog Boxes


static void Simple_Dialog(Args _args)
{
dialog dlg;
dialogGroup dlgGroup;
dialogField dlgField;
;
dlg = new dialog("Simple Dialog");
dlgGroup = dlg.addGroup("Customer");
dlgField = dlg.addField(TypeID(custAccount),"Account Number");

if (dlg.run())
{
print dlgField.value();
pause;
}
}

Pack and Unpack

Pack and Unpack


ClassDeclaration

class Tutorial_RunbaseBatch extends RunBaseBatch
{
    // Packed variables
    TransDate       transDate;
    CustAccount     custAccount;

    // Dialog fields
    DialogField     dlgCustAccount;
    DialogField     dlgTransDate;

    #define.CurrentVersion(1)
    #define.Version1(1)
    #localmacro.CurrentList
        transDate,
        custAccount
    #endmacro
}

Dialog


public Object dialog()
{
    DialogRunbase       dialog = super();
    #resAppl
;
    dialog.addImage(#ImageEmployee);
    dialog.addInfoImage();
    dlgTransDate = dialog.addFieldValue(typeid(TransDate),transDate);

    dialog.addTabPage("@SYS76580");
    dlgCustAccount = dialog.addFieldValue(typeid(CustAccount),custAccount);

    return dialog;
}

Pack

public container pack()
{
    return [#CurrentVersion,#CurrentList];
}



Unpack

public boolean unpack(container packedClass)
{
    Version version = RunBase::getVersion(packedClass);
;
    switch (version)
    {
        case #CurrentVersion:
            [version,#CurrentList] = packedClass;
            break;
        default:
            return false;
    }

    return true;
}

Main


static void main(Args args)
{
    Tutorial_RunbaseBatch    tutorial_RunBase;
 
;
    tutorial_RunBase = Tutorial_RunbaseBatch::construct();

    if (tutorial_RunBase.prompt())
    {
        tutorial_RunBase.run();
    }

MaCROS

Macros


#define.Text('This is a test of macros')
#define.Number(200)

static void Datatypes_macro_library(Args _args)
{
    // Referencing macro library has to be done in the class declaration
    // or in the declaration like in this example
    #MacroTest

    ;
    info(strfmt("Text: %1. Number: %2", #Text, #Number));
}


Local Macro

static void Local_Macro(Args _args)
{
    // Define the local macro    #localmacro.WelcomeMessage    {        info("Welcome to Carz Inc.");
        info("We have the best offers for rental cars");
    }

    #endmacro;  

    // Use the local macro  
    #WelcomeMessage
}


SQL/SSRS Interview questions I thought of blogging some SQL/SSRS interview questions.

Below are some. I will add more, when I complete the compilation 1. What is OLTP(Online Transaction Processing)? OLTP stands ...