Alfasith AX

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

Friday, May 30, 2014

Expression to get full company name in SSRS

Hi,

=Microsoft.Dynamics.Framework.Reports.DataMethodUtility.GetFullCompanyNameForUser( Parameters!AX_CompanyName.Value,Parameters!AX_UserContext.Value)

Regards,

Expression to get only system date in SSRS

Hi,

=FormatDateTime(Now, DateFormat.ShortDate)

Regards,

Thursday, May 29, 2014

Get vendor information in Dynamic AX

Hi,

static void GetVendInfo_Alfasith(Args _args)
{
    VendTable       vendTable;
    ;
    vendTable =  VendTable::find("1101"); // select the vendor account here
    info(strFmt("Name: %1", vendTable.name()));
    info(strFmt("Telephone    : %1", vendTable.phone()));
    info(strFmt("email        : %1", vendTable.email()));
    info(strFmt("Website/ blog: %1", vendTable.url()));
    info(strFmt("Fax          : %1", vendTable.telefax()));
    info(strFmt("Address      : %1", vendTable.postalAddress().Address));
}



Regards,

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,

Friday, May 23, 2014

Product and product related information are stored in following tables Dynamic AX

Hi,
Table Name Table Description
EcoResProduct The EcoResProduct table stores products and is the base table in the products hierarchy.
EcoResProductMaster The EcoResProductMaster table stores product masters.
EcoResProductIdentifier The EcoResProductIdentifier table contains a product identification that is available for users.
EcoResDistinctProduct The EcoResDistinctProduct table stores products.
EcoResDistinctProductVariant The EcoResDistinctProductVariant table stores product variants.
EcoResProductDimensionGroup The EcoResProductDimensionGroup table contains information about a dimension group.
EcoResProductDimensionGroupProduct The EcoResProductDimensionGroupProduct table stores information about relationships between products and dimension groups.
EcoResColor The EcoResColor table stores color names.
EcoResSize The EcoResSize table stores size names.
EcoResConfiguration The EcoResConfiguration table stores configuration names.
EcoResProductMasterColor The EcoResProductMasterColor table stores information about colors assigned to product masters.
EcoResProductMasterSize The EcoResProductMasterSize table stores information about sizes that are assigned to product masters.
EcoResProductMasterConfiguration The EcoResProductMasterConfiguration table stores information about configurations assigned to product masters.
EcoResProductVariantColor The EcoResProductVariantColor table stores information about the colors that are assigned to product variants.
EcoResProductVariantSize The EcoResProductVariantSize table stores information about the sizes that are assigned to product variants.
EcoResProductVariantConfiguration The EcoResProductVariantConfiguration table stores information about the configurations that are assigned to product variants.
EcoResProductMasterDimensionValue The EcoResProductMasterDimensionValue table is the base table in the product model dimension hierarchy.
EcoResProductVariantDimensionValue The EcoResProductVariantDimensionValue table is the base table in the product variant dimension hierarchy.
EcoResProductDimensionAttribute The EcoResProductDimensionAttribute table contains definitions of product dimension attributes (categories).
EcoResInstanceValue The EcoResInstanceValue table contains the definitions of the instances of the components or products.
EcoResProductInstanceValue The EcoResProductInstanceValue table contains definitions of values for the instances of attributes of a product.
InventTable The InventTable table contains information about items.
InventTableModule The InventTableModule table contains information about purchase, sales, and inventory specific settings for items.
InventItemLocation The InventItemLocation table contains information about items and the related warehouse and counting settings. The settings can be made specific based on the items configuration and vary from warehouse to warehouse.
InventItemSalesSetup The InventItemSalesSetup table contains the default settings for items, such as site and warehouse. The values are related to sales settings.
InventItemInventSetup The InventItemInventSetup table contains the default settings for items, such as site and warehouse. The values are related to inventory settings.
InventItemPurchSetup The InventItemPurchSetup table contains the default settings for items, such as site and warehouse. The values are related to purchase settings.
InventItemSetupSupplyType The InventItemSetupSupplyType table contains information about the sourcing of items.
InventDim The InventDim table contains values for inventory dimensions.
InventDimCombination The InventDimCombination table contains variants of items. The variants are created as product variants that are based on product dimensions such as size, color, and configuration. These variants are replicated to the legal entity.
Regards,

Job to update the customized receipt profile in Retail - POS - Dynamic AX

Hi,

The job (to push the receipt format customization in to POS data base).
A-1090 - Registers
N-1090 - Registers.

Regards,


Friday, May 16, 2014

Job to check the table before insert in to that concern table for the existence in Dynamic AX

Hi,

static void AlfasithCode2CheckB4Insert(Args _args)
{
container contain;
    str 30 Name;

    int i;
    ContanerTable   ContanerTableLoc;
    contain = ["Ram","Sam","Mam","Kamal","Ram","Raja","Rani","Kamal"];
    for(i = 1; i <= conLen(contain) ;i++)
    {
        name = conPeek(contain,i);
    select ContanerTableLoc where ContanerTableLoc.Names == name;
            if(!ContanerTableLoc)
            {
                ContanerTableLoc.Names = Name;
                ContanerTableLoc.insert();
            }
    }
    info("Process completed...");
}

Regards,

Job to release the product for current legal entity in Dynamic AX

Hi,

static void ReleaseProductAlfasith(Args _args)
{
    EcoResProductVariantCreationMgr ProductVariantCreationMgr;
    _args = new Args();
    _args.record(EcoResProduct::findByProductNumber("000149_202"));
    ProductVariantCreationMgr  = EcoResProductVariantCreationMgr::newFromArgs(_args);
    ProductVariantCreationMgr.parmCalledFromJob(true);
    ProductVariantCreationMgr.buildVariantSuggestions();
    ProductVariantCreationMgr.run();
    info("Item Sucessfully released");
}


Regards,

"SysDictTable Object not initialized" when transferring the data from staging table to target table for product entity in DMF- Dynamic AX

Hi,

This is the error I'm receiving when importing the product entity using DMF.
while transferring record from staging to target table.

Sol:
Just add following code in
Class: DMFEntityWriter,
method : Write,
line : 217
Note:   inside the parent while loop in line 215.

if (   currentNode.ChildDataSource == 'RetailInventTable'  )
{
continue;
}

Regards,

DMF Error: Duplicate tag exists in file - Dynamic AX

Hi,

Please check your file that you uploading to staging table.
Sol.
Header name (column name) is repeated, just check it remove it.
Note: NO COLUMN NAME SHOULD USER DEFINED OR REPEATED.

Regards,

Tuesday, May 13, 2014

Parent shold not be closed unless child form is closed in Dynamic AX

Hi,

// you are writting on formA parent form
Args args;
FormRun formRun;
;
super();
args = new Args(formstr(FormB)); // FormB is child form
args.caller(element);

formRun = classFactory.formRunClass(args);
formRun.init();
formRun.run();
formRun.wait(); // this waits till child closes, unless child closes u cant close parent/ current form
formRun.detach(); // this will not wait for child form to close..

Regards,

Wednesday, May 7, 2014

Delete actions are used in Dynamic AX

Hi,

Meaning: If you are deleting a record in the master table , how should it react if it has got transaction records

4 type of delete actions

None - IT WILL DELETE MASTER RECORDS AND WILL NOT DELETE CHILD RECORDS

Cascade - IT WILL FIRST DELETE THE CHILD RECORDS AND COME BACK AND DELETES THE MASTER RECORD

Restricted- IT WILL NOT DELETE ANY OF THE RECORDS [MASTER AND CHILD] - IT WILL THROW A WARNING MESSAGE - TRANSACTIONS EXISTS IN XYZ TABLE.CANNOT DELETE THE RECORD.

C + R [Cascade + restricted] - OPTION IS LEFT TO THE USER TO DELETE OR NOT

Note: Delete actions should be always be set on Master table

Regards,

Standard data type & Composite data types in dynami AX

Hi,

DataType

AX - Primitive and composite

primitive:

1) int [32]
2) int 64 - long int [ credit card numbers, debit card numbers]
3) real - decimal points example : 12346.00 [12 digits]
4) str  - sequence of characters [ lengTH - 10]

5) Base Enums: enumerations [ fixed set of constants/literals]

  - constant - will never change

example : week [ sunday 0, m1, t 2, we 3, thu 4, fri 5, sat 6]
 Year [j........d]
gender [ m, f, uk]

enum value starts with 0
Largest value it can hold is 250

6) Date - in order to hold any date values [mm/dd/yyyy], dd/mm/yyyy 20-Aug-2010

7) Time - integer

8) DateTime - 12/23/2011 2:00:05 PM

9) 5.0 version of AX - utcDateTime -  Universal time control data time

example: if you do the transaction @ 6 PM IST - the transactions transaction can be see @ 8:30 AM EST in US.

10) GUID - Global unique identifier - 24 digit hexa decimal number which system will generate automatically

 example : 23hgdh-12321h-12nb23-haifa9


Composite data types:

1) Arrays -  collection of similar datatypes:

1) Index starts with 1

EXAMPLE :

str names[11]; //static array
// dynamic array str names[]
names[1] = "Kabir";
names[2] = "Khan";
;
;
;
names[8] = "Alfasith";


2) Containers :

Large objects[BLOB] - Images, files, pdfs, vidoes etc


Regards,

Code to create general journal in Dynamic AX

Hi,

static void CreateGLJournal(Args _args)
{
    AxLedgerJournalTable journalTable;
    AxLedgerJournalTrans journalTrans;
    DimensionDynamicAccount     offsetDimensions, bankaccount;
    DNIPMIPParameters   parameters;
    dimensionStorage    dimensionStorage;
    LedgerAccountContract   ledgerAccountContract;
    DimensionValue  dimvalue;
    LedgerDimensionAccount dimaccount, ledgeracc;
    LedgerJournalTable  ledgerJournalTable;
    LedgerJournalTrans  ledgerJournalTrans;
    DNIPMPfInvestmentLines  DNIPMPfInvestmentLines;
    DNIPMPfInvesmentTable   table;
   // "??CEU-000025";
    int i;
    ;
    i = 1;
    journalTable = new AxLedgerJournalTable();
    journalTrans = new AxLedgerJournalTrans();


    journalTable.parmJournalName("GenJrn");
    journalTable.save();
    select * from parameters;
    while(i<5)
    {
    journalTrans.parmJournalNum(journalTable.ledgerJournalTable().JournalNum);
    journalTrans.parmTransDate(systemDateGet());
    dimvalue = DimensionStorage::getMainAccountNumFromLedgerDimension(parameters.Payment);
    dimaccount = DimensionStorage::getDefaultAccountForMainAccountNum(dimvalue);
    ledgeracc = DimensionDefaultingService::serviceCreateLedgerDimension(dimaccount);
    journalTrans.parmAccountType(LedgerJournalACType::Ledger);
    journalTrans.parmLedgerDimension(ledgeracc);

    journalTrans.parmAmountCurDebit(2000);
    bankaccount = DimensionStorage::getDynamicAccount('USA OPER', LedgerJournalACType::Bank);
    journalTrans.parmOffsetLedgerDimension(bankaccount);
    journalTrans.parmOffsetAccountType(LedgerJournalACType::Bank );
    journalTrans.parmCurrencyCode("USD");
    //journalTrans.currentRecord().insert();
    journalTrans.save();
    i++;
    }

    info(strFmt("Journal %1 created", journalTable.ledgerJournalTable().JournalNum));

}

Regards,

Adding indicators to the table in Dynamic AX

Hi,

display ImageRes showIndicatorImage()
{
    #resAppl

    int ret;
    ;
    ret = 0;
//By Alfasith for the requirement of red and green indicator
    if (this.ExpiryDate > systemDateGet() )//  == AnotherTable::find(this.ForeignKeyField).MyField)
        ret = #ImageAgingPeriod2_small;
   else
        ret = #ImageAgingPeriod5_small;

    return ret;
}

Regards,

Generate random password in Dynamic AX

Hi,

Just like OTP (one time password) for email this below code generates for alphabet.

static void Generate_Password_Random()
 {
     int i;
     RandomGenerate random = new RandomGenerate();
     str password;
     int passwordLength = 8;
     ;

     for (i=1; i<= max(2, passwordLength); i++)
     {
         if (i mod 2)
             password += num2char(random.randomInt(char2num('a', 1), char2num('z', 1)));
         else
             password += num2char(random.randomInt(char2num('0', 1), char2num('9', 1)));
     }

     info(password);
 }

Code to get the line no to grid in Dynamic AX

Hi,

use below code in the create method of the form in data source level.

 select maxOf(SequenceNumber) from dNPhaseLoc where dNPhaseLoc.DNModularID == DNModule.DNModularID;
 if(DNPhase)
      DNPhase.SequenceNumber = dNPhaseLoc.SequenceNumber +1;
  else
        DNPhase.SequenceNumber = 1;

//Just add SequenceNumber as interger field for your table with reference to header datasoure record you need to use where clause.
Thus line no will be created.

Regards,

Code to call number sequence in Dynamic AX

Hi,

NumberSeq   num;
num = NumberSeq::newGetNum(DNAxaptaModule::ModularID());
//DNAxaptaModule is the table that number seq presents
AxaptaModule.DNModularID  = num.num();
//AxaptaModule is the local variable for the same above table

Regards,

Import license for Dynamic AX

Hi,

1. Click Administration > Setup > System > License information.
2. Click Load license file to import the license codes from a file.
The Load license file dialog box appears.
3. Click the folder icon and browse for your license file.
4. Click OK.
The Configuration dialog box appears and you are asked if you want to synchronize your database.
5. Click Yes.
6. Close the License information window.

Regards,

The error is Deserialization failed: Requested value 'EnterpriseCore64' was not found

Hi,

Solution : Installl culative updates for SQL server 2012.

Regards,

How find size of recordsortedlist in D365/AX 2012

Hi, This is the continuity of the previous article where we are now getting the size of recordsortedlist . if(recordsortedlist.len() >1) ...