Alfasith AX

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

Sunday, May 25, 2014

insert_recordset in dynamic AX - Insert all the records to duplicate table.

Hi,

Normally we used to insert the record like below to transfer the record from 1 table to another.

SourceTableName SourceTbl;
DestinationTableName DestinationTbl;
int records;
ttsBegin;
while select * from SourceTbl
    where SourceTbl.tabId > 0
{
    DestinationTbl.Field1        = SourceTbl.Field1;
    DestinationTbl.Field2       = SourceTbl.Field2;
    DestinationTbl.Field3        = SourceTbl.Field3;
    //So on fields... but it should n=match with datatype / EDT /Enum
    DestinationTbl.insert();
    records++;
}
ttsCommit;
info(records);
/********************************************/
but AX there is another feature to insert the bulk of record without transmission delay in reduced set of codes.

Same above code is reduced to.

insert_recordset DestinationTbl 
    select SourceTbl
         // where SourceTbl.Feild1 <= 100 
// If you have any condition to filter else al the record will be transfer
 /*****************************************************/
If you want to map the fields you need to.
insert_recordset DestinationTbl (Feild1, Feild2, Feild3...)
    select Feild1, Feild2, Feild3... 
        from SourceTbl
            where SourceTbl.Feild1 <= 100; //if condition 

Regards,




Saturday, May 24, 2014

To get enum value from the enum field in Dynamic AX

void ToGetEnumFromValue(Args _args)
{
    ABC ABC;
    str val = "B";
    int m;
    //m = enum2int(str2enum(ABC,val));
    //print enum2int(str2enum(ABC,val));
    print enum2str(str2enum(ABC,val));
    pause;
}

Look up filter using enum value in Dynamic AX

Hi,

void lookupJobId(FormControl control)
{
    Query                   query = new Query();
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange         queryBuildRange;
    SysTableLookup          sysTableLookup;
    ;

    //Create an instance of SysTableLookup with the form control passed in
    sysTableLookup = SysTableLookup::newParameters(tablenum(InventTable), this);

    //Add the fields to be shown in the lookup form
    sysTableLookup.addLookupfield(fieldnum(InventTable, ItemId), true);
    sysTableLookup.addLookupMethod(tablemethodstr(InventTable, ItemName), false);

    //create the query datasource
    queryBuildDataSource = query.addDataSource(tablenum(InventTable));
    queryBuildRange = queryBuildDataSource.addRange(fieldnum(InventTable    ,ABCValue));
    queryBuildRange.value(enum2str(ABC::A)); //Example of Enum value

    //add the query to the lookup form
    sysTableLookup.parmQuery(query);

    // Perform lookup
    sysTableLookup.performFormLookup();
}
/***************************************************************/
If the filter with reference to the enum field already existing in form then.

void lookupJobId(FormControl control)
{
    Query                   query = new Query();
    QueryBuildDataSource    queryBuildDataSource;
    QueryBuildRange         queryBuildRange;
    SysTableLookup          sysTableLookup;
    ;

    //Create an instance of SysTableLookup with the form control passed in
    sysTableLookup = SysTableLookup::newParameters(tablenum(InventTable), this);

    //Add the fields to be shown in the lookup form
    sysTableLookup.addLookupfield(fieldnum(InventTable, ItemId), true);
    sysTableLookup.addLookupMethod(tablemethodstr(InventTable, ItemName), false);

    //create the query datasource
    queryBuildDataSource = query.addDataSource(tablenum(InventTable));
    queryBuildRange = queryBuildDataSource.addRange(fieldnum(InventTable    ,ABCValue));
//Direct filter for enum ABC::A
    queryBuildRange.value(enum2str(ABC::A)); //Example of Enum value
//else
//consider the enum fields is stored in header table as HeaderTableName.EnumField
//Make sure that EnumField should be ABC enum

    queryBuildRange.value(enum2str(str2enum(ABC,HeaderTableName.EnumField)));

    //add the query to the lookup form
    sysTableLookup.parmQuery(query);

    // Perform lookup
    sysTableLookup.performFormLookup();
}


Regards,

Upload image in to form / Application photo in Dynamic Ax

Hi,

// Use this below code in clicked method for your button placed in form.
str filename;
FileNameFilter filter = ['JPG files','*.jpg'];
Bindata binData;
Image signatureImage = new Image();

super();

filename = Winapi::getOpenFileName(element.hWnd(), filter, '', "Upload your image", '', '');

binData = new BinData();

if (binData.loadFile(filename))
{
    signatureImage = binData.getData();
    WindowField.image(signatureImage); // WindowField - is the window field and make it auto declaration  : Yes
    WindowField.widthValue(signatureImage.width());
    WindowField.heightValue(signatureImage.height());
    element.resetSize();
    element.unLock();
}
Note:  this code stows the record but not stores the record in table.

Regards,

To get current User name in Dynamic AX

Hi,

print xUserInfo::find().id;
   
print xUserInfo::find().name;
   
pause;

Note: if it print ADMIN nothing to worry, because it printing your exact id only. this will be Admin when you,  working on domain project / project in domain instance this will print current user perfectly.

Regards,

SQL tutorial for X++ / Dynamic AX

Hi,

SQL tutorial for AX buds.

SELECT - extracts data from a database
UPDATE - updates data in a database
DELETE - deletes data from a database
INSERT INTO - inserts new data into a database
CREATE DATABASE - creates a new database
ALTER DATABASE - modifies a database
CREATE TABLE - creates a new table
ALTER TABLE - modifies a table
DROP TABLE - deletes a table
CREATE INDEX - creates an index (search key)
DROP INDEX - deletes an index
--------------------------------------
Consider this below table as example for upcoming scenarios.
                  Student
--------------------------------------
studentID Name Gender Native
Stu001 Fathima Female IND
Stu002 Faridth Male IND
Stu003 Faheed Male KSA
Stu004 Fakrudeen Male KSA
Stu005 Firdose Female IND
Stu006 Fahima Female KSA
---------------------------------------

All the SQL syntax is not applicable for X++;

SQL Tutorial
SQL Select Basic select concern record while SELECT field_Name FROM table_name
SQL Distinct List unique records while SELECT DISTINCT field_Name FROM table_name 
SQL Where Where condition while SELECT field_Name FROM table_name where Table_Name.Field_Name ==/=< conditions
SQL And & Or Show only IND female student while SELECT StudentID FROM Student where  Student.Gender == Gender::Female && Student.Native == "IND"
Show all female record, IND native also while SELECT StudentID FROM Student where  Student.Gender == Gender::Female || Student.Native == "IND"
SQL Order By Sort the record while SELECT DISTINCT field_Name FROM table_name ORDER BY table_name.field_Name ASC/DESC
SQL Insert Into MyTable  MyTable;  ttsBegin;  select MyTable ;  MyTable.AccountNum = '1101'; MyTable.Name = 'MyName';  MyTable.insert();  ttsCommit;
SQL Update Student Student; ttsBegin;  select forUpdate Student where Student.StudentID= "Stu0002"; Student.StudentID = 'Stu0009'; Student.Name = "Rahima"; Student.update();  ttsCommit;
SQL Delete static void DeleteMultiRow1bJob(Args _args)
{
    MyWidgetTable tabWidget; // extends xRecord.
    ;
    ttsBegin;
    while select
        forUpdate
        tabWidget
        where tabWidget .quantity <= 100
    {
        tabWidget .delete();
    }
    ttsCommit;
}
SQL Select Top Code fastup the search and once found it will search for remaining data select FirstOnly PersonnelNunber where HcmWorker.PersonnelNumber == "0000567";
SQL Between There is no between in X++ but while select Table_Name where Table_Name.Field_Name >= RangeFromValue && Table_Name.Field_Name <= RangeToValue
SQL Wildcards while SELECT DISTINCT field_Name FROM table_name 
SQL Not Null while select Table_Name where Table_Name.Field_Name != Null


Regards,

Get a table ID in SQL / table browser - D365

Hi select ID from SysTableIdView where  SysTableIdView .Name = 'CustTable' <URL>/?cmp=<CompanyID>&mi=sysTableBrowser...