Wednesday, May 20, 2015

Example of Table Inheritance in Ax 2012

Hi All In Microsoft Dynamics AX 2012, tables can inherit, or extend, from the tables that are situated above them in a hierarchy. A base table contains fields that are common to all tables that derive from it. A derived table inherits these fields, but also contains fields that are unique to its purpose. Each table contains the Support Inheritance and Extends properties, which can be used to control table inheritance. First we need understand that when we need to apply this inheritance methodology to tables. First we need to identify the Parent table and its siblings like
Here ‘Basic Info’ is the Parent table containing fields that are required for its child table i.e. CompnayTable and EmpTable. And these tables have their own fields as well.Now to design a Inheritance pattern we need to consider following important things:

·         We can only apply inheritance on regular tables not on Temp or Memory tables
·         A type discriminator field must be defined on any table inheritance hierarchy created in the AOT. The field must be defined as an int64 type on the root table, with the name of the field set to InstanceRelationType.
·         The InstanceRelationType field of the root table is read-only and stores the TableIDs of record instances; it is populated automatically by Microsoft Dynamics AX 2012.
·         Also we can only set the table properties for the table inheritance only when there are no fields in the table.
·         If these requirements are not met, a compilation error will occur when the table inheritance hierarchy is compiled.

Let create parent Table ‘BasicInfo’
Setting its SuppourtInheritance Prpoerty to Yes


When you save and compile,it will give following error


For this we need to create a discriminator; name ‘InstanceRelationType’ and of type Int64.Now I have created a field including discriminator



Finally I have set another table property ‘InstanceRelationType’ to ‘InstanceRelationType’  field


And when I compiled, the error is gone now.
Now we have to create Two child tables
EmpTable:
First I have set the ‘SupportInheritance Property to Yes.





And finally added all fields.



CompanyTable:
Same as what already we have done for EmpTable
Now when I compile it still give the two errors i.e.



Basically these errors indicates that the automatic relation that have been created in the child table,have the same relation name and so it is showing duplicate so for this I have changed the name See below screen shot
ScreenShot (see below)








And that’s it we have created Parent-child hierarchy table .
Finally, we need to also set the ‘Abstract’ property of the parent table to ‘Yes’ and for this we need to understand below.
Abstract versus concrete tables:
Tables in a table inheritance hierarchy can be defined as either abstract or concrete, depending on whether the table property Abstract is set to Yes or No. Records can only be created for concrete table types. Any attempt to create a record and insert it in an abstract table will result in a run-time error. The position of the table in the inheritance hierarchy does not restrict its ability to be defined as abstract.










Sunday, May 17, 2015

Code for How to get the Field name value based on Lookup id value of another field in a table

public void modifiedField(FieldId _fieldId)
{
    StudentTable_S StudentT;
    switch(_fieldId)
    {
    case fieldNum(FacultyTable_s,F_StudentId):
    Select StudentT where StudentT.StudentId==this.F_StudentId;
    this.F_StudentName=StudentT.StudentName;

    break;
    default:
    break;
    }
    super(_fieldId);

}

Note: it retrieves the value of F_StudentName based on F_Id value

Friday, May 15, 2015

Sequence of calling form methods in AX 2012

Sequence of calling form methods in AX 2012


This gives the information of method calls in the form level while
1. Opening the Form.
2. Creating/Updating/Deleting the record in the Form.
3. Closing the Form.

Sequence of Methods calls while opening the Form

Form --- init ()
Form --- Datasource --- init ()
Form --- run ()
Form --- Datasource --- execute Query ()
Form --- Datasource --- active ()

Sequence of Methods calls while closing the Form

Form --- canClose ()
Form --- close ()

Sequence of Methods calls while creating the record in the Form

Form --- Datasource --- create ()
Form --- Datasource --- initValue ()
Table --- initValue ()
Form --- Datasource --- active ()

Sequence of Method calls while saving the record in the Form

Form --- Datasource --- ValidateWrite ()
Table --- ValidateWrite ()
Form --- Datasource --- write ()
Table --- insert ()

Sequence of Method calls while deleting the record in the Form

Form --- Datasource --- validatedelete ()
Table --- validatedelete ()
Table --- delete ()
Form --- Datasource --- active ()

Sequence of Methods calls while modifying the fields in the Form
Table --- validateField ()
Table --- modifiedField ()

Method Calling sequences of Table

Method Calling sequences of Table


When you press CTR+N
inItValue()->

When you change data in a field
validateField()  -> validateFieldValue() ->  ModifiedField() ->  ModifiedFieldValue()

When you close the table after entering some data
validateWrite() - > Insert()  -> aosValidateInsert()

When you open the table which will contain some data
If table will contain 10 records this method is called 10 times
aosValidateRead()

When you Save the Record for the first time

validateWrite() ->Insert() - > aosValidateInsert()
When you modify the record and saving

validateWrite() -> update() - > aosValidateUpdate()

When you delete the record
validateDelete() -> delete() -> aosValidateDelete()

Tuesday, May 12, 2015

Code for status change for menuitem button(access a class through menuitem button) in a listpage based on enum value

class EmpAccountstatusChange_s
{
    EmpFullDetails_s emp;//table declaration

}

public static void main(Args args)
{
    EmpFullDetails_s emp;//table declaration
    EmpAccountstatusChange_s EmpASC ;//class declaration
    EmpASC = new EmpAccountstatusChange_s();


    emp=args.record();
    emp.AccountStatus_s=AccountStatus_s::Active;
}

Note:If u click on statuschange with selection of inactive field then it become active after clicking status change button

Wednesday, May 6, 2015

Convert Functions in ax 2012

Convert Functions  in ax 2012

1.any2Enum Function
Converts an anytype value to the Name property value of an element in the target enum.
Syntax:
enum any2Enum(anytype object)

Return Value:

The value of the Name property for whichever element on the target enum has a Value property that matches the input parameter.

Remarks:

The object parameter can be of most data types, but useful data is only obtained by using a parameter of type str or int.

This input object parameter refers to the Value property of an individual element in the target enum.

Example:
    NoYes myNoYes;  // NoYes is an enum.
    int i;
    str s;

    i = 0;  // An int that will be converted.
    myNoYes = any2Enum(i);
    Global::info(strfmt("'%1' - is the output, from input of the %2 as
     int.", myNoYes, i));
       
    s = "1";  // A str that will be converted.
    myNoYes = any2Enum(s);
    Global::info(strfmt("'%1' - is the output, from input of the %2 as                                                        
     str.", myNoYes, s));
    OP: 'No' - is the output, from input of the 0 as int.
         'Yes' - is the output, from input of the 1 as str.

2.any2Date Function:

Converts an anytype value to a date value.
Syntax: date any2Date(anytype object)
Note:-Object:The value to convert to a date.
 
Example:
    date getdate;
    str s;
    int i
    ;
    s="2012 2 12"; //yyyy mm dd
    getdate=any2date(s);
    {
    info(strFmt("%1",getdate));//OP:2/12/2012
    }
    i=40361;
    getdate=any2date(i);
     {
    info(strFmt("%1",getdate));//Op: 7/4/2010
    }

3.any2Guid Function:

Converts the specified anytype object to a GUID object.

Syntax: guid any2Guid(anytype object)
 

4.any2Int Function :

Converts an anytype value to an int value.

Syntax: int any2Int(anytype object)

5.any2Int64 Function:

Converts an anytype object to an int64 object.

Example:

        int Sint;

    str s;
    NoYes Ny;
    real re;
   ;
    s="55";
    Sint=any2int(s); or Sint=any2int64(s);
    info(strFmt("%1",s));//op:55
   
    Ny=NoYes::Yes;
    Sint=any2int(Ny);
    info(strFmt("%1",Sint));//Op:1
   
    re=5.99;
    Sint=any2int(re);
    info(strFmt("%1",Sint));//Op:5

6.any2Real Function:

Converts an anytype value to a real value.

Syntax:

real any2Real(anytype object)

Example:

    real Re;
    str s;
    int i;
    NoYes ny;
    ;
    s="5.66";
    Re=any2real(s);
    info(strFmt("%1",Re));//Op:5.66
   
    i=99;
    Re=any2real(i);
    info(strFmt("%1",Re));Op:99.00
   
    ny=NoYes::No;
    Re=any2real(ny);
    info(strFmt("%1",Re));Op:0.00   

7.any2Str Function:

Converts an anytype value to a str value

Syntax:

Str any2str(anytype object)

Example:

    str mystring;
    anytype a;
    NoYes ny;
    int i;
    ;
    a="delhi64";
    mystring=any2str(a);
    info(strFmt("%1",mystring));//Op:delhi64
   
    a=NoYes::No;
    mystring=any2str(a);
    info(strFmt("%1",mystring));

Op:0(because it is the value of specified enum element)

8.char2Num Function:

Converts a character in a string to the ASCII value of the character.

Syntax:

int char2Num(str text, int position)

Example:

    int i;
    str s;
    ;
    s="shiva";
    i=char2num(s,5);
    info(strFmt("%1",i));
Op:97

9.date2Num Function:

Converts a date to an integer that corresponds to the number of days since 1 January, 1900.

Syntax: int date2Num(date _date)
_date:date to convert;
 
Example:
  date d;
    int i;
    ;
    d=today();
    i=date2num(d);
    info(strFmt("%1",i));
                or
         i=date2num(29\04\2015);
    info(strFmt("%1",i))

Op: 42121

Note: Retrives the number of days between from 1 January, 1900 and the specified date.

10.date2Str Function:

Converts the specified date to a string

Syntax: str date2Str(
    date date,
    int sequence,
    int day,
    int separator1,
    int month,
    int separator2,
    int year
    [, int flags = DateFlags::None])

 

Parameters

 
Parameter
Description
date
The date to convert.
sequence
A three digit number that indicates the sequence for the components of the date, 1 for day, 2 for month, and 3 for year.
day
A DateDay enumeration value that indicates the format for the day component of the date.
separator1
A DateSeparator enumeration value that indicates the separator to use between the first two components of the date.
month
A DateMonth enumeration value that indicates the format for the month component of the date.
separator2
A DateSeparator enumeration value that indicates the separator to use between the last two components of the date.
year
A DateYear enumeration value that indicates the format for the year component of the date.
flags
A DateFlags enumeration value that indicates whether the language settings on the local computer should be used to calculate the proper left-to-right or right-to-left sequence in the returned string.
     

Return Value

A string that represents the specified date.

Example:
   
  date Todaydate=today();
    str s;
    ;
    s=date2str(Todaydate,123,DateDay::Digits2,DateSeparator::Slash,DateMonth::Digits2,DateSeparator
    ::Slash,DateYear::Digits4);
   
    info("today is"+s);Op:29

or

//date Todaydate=today();

    str s;
    ;
    s=date2str(Today(),123,DateDay::Digits2,DateSeparator::Slash,DateMonth::Digits2,DateSeparator
    ::Slash,DateYear::Digits4);
   
    info("today’s date is" +s);

Op: today’s date is 29/04/2015

11.datetime2Str Function:

Converts a utcdatetime value into a string.

Syntax: str datetime2Str(
    utcdatetime datetime
    [, int flags = DateFlags::None])

Example:

utcdatetime utc2 = 1959-06-17T15:44:33;
    str s3;
    ;
    s3 = datetime2Str( utc2 );
    info( s3 );
Op: 4/29/2015 03:44:33 pm

12.formattedStr2Num:

Converts a semi-numeric string into a real number.

Syntax:real formattedstr2Num(str _text)

Example:

print formattedstr2Num("123.45");//Op:123.45
    pause;
or
real r;
r=formattedstr2Num("123");
info(strFmt("%1",r));//Op:123.00
or
int i;
i=formattedstr2Num("123.01");
info(strFmt("%1",i));Op:123
or
print formattedstr2Num("356890");
    pause;//Op:356,890.00
           or
print formattedStr2num("12+1200");
    pause;Op:12,12.00

13.guid2Str Function:

Converts the specified GUID object to the equivalent string.

Syntax: str guid2String(guid _uuid)
Example:
    guid _guid;
    str stringGuid;
    ;

    _guid = Global::guidFromString
        ("{12345678-1234-1234-1234-123456789abc}");
    print strfmt("GUID is %1", _guid);
   

    stringGuid = guid2str(_guid);
    info("String GUID is " + stringGuid);
Op: String GUID is {12345678-1234-1234-1234-123456789ABC}

14.int2Str Function:

Converts an integer to the equivalent string.

Syntax:

str int2Str(int integer)

15.int642Str Function:

Converts the specified integer parameter to the equivalent text string.
 
Syntax: str int642Str(int64 integer) 
 
Example:
    str s;
    int i=64;
    ;
    s=int2str(i);
    info(strFmt("%1",s));Op:64;
           or
    info ("This is int2Str, value is " + int2Str(intMax()));
    info ("This is int642Str, value is " + int642Str(int64Max()));
Op: This is int2Str, value is 2147483647
    This is int642Str, value is 9223372036854775807

16.str2Int Function:

Converts a string to the equivalent integer.

Syntax: int str2Int(str _text)
Example:
    int i;
    str s="65";
    ;
    i=str2int(s);
    info(strFmt("%1",s));//Op:65

17.num2Char Function:

Converts an integer to the corresponding ASCII character.

Syntax: str num2Char(int figure)

Example:
    str s;
    s=num2char(35);
    info(strFmt("%1",s));//Op:#

18.num2Date Function:

Retrieves the date that corresponds to the specified number of days after 01\01\1900.

Syntax:

date num2Date(int _days)
Example:
    date s;
    s=num2date(36356);
    info(strFmt("%1",s));
OP: 7/17/1999

19.num2Str Function:

Converts a real number to a string.

Syntax: str num2Str(
    real number,
    int character,
    int decimals,
    int separator1,
    int separator2)
Example:
    real num=0.1234567891123456;
    info(num2str(num,0,10,1,3));//OP: 0.1234567891
    info(num2str(num,0,17,1,3));//OP: 0.12

20.str2Enum Function:

Retrieves the enum element whose localized Label property value matches the input string.

Syntax: enum str2Enum(enum _type, str _text)

Example:

    BankAccountType bat;
    str sEnumValueLabelLocalized;
    int nInt;

    // enum2str.
    sEnumValueLabelLocalized = enum2str
        (BankAccountType::SavingsAccount);
    info("Localized friendly string: "
        + sEnumValueLabelLocalized);

    // str2enum.
    bat = str2Enum(bat, sEnumValueLabelLocalized);
    nInt = bat;
      info("nInt = " + int2str(nInt));
Op: Localized friendly string: Savings account
nInt = 1

21.str2Date Function:

Converts the specified string to a date value.

Syntax:

date str2Date(str _text, str _sequence)
 
text
The string to convert to a date value.
_sequence
A three digit integer that describes the positions of the day, month, and year in the string to convert.

Remarks

Use the following values to specify the positions of the day, month, and year in the _sequence parameter:
·         day: 1
·         month: 2
·         year: 3

 

Example:
    date d;
   d=str2Date("02/11/2012",123);
   info(strFmt("%1",d));
         Op: 2/11/2012

22.str2Datetime Function:

Generates a utcdatetime value from the specified string of date and time information.

Syntax:

utcdatetime str2datetime( str text, int sequence )

 

Example:

    utcdatetime utc3;
    str sTemp;
    ;
    utc3 = str2datetime( "1985/02/25 23:04:59" ,321 );
    sTemp = datetime2str( utc3 );
    //print( "sTemp == " + sTemp );
    info(sTemp);

Op: 2/25/1985 11:04:59 pm

23.str2Guid Function:

Converts a string to a GUID object.

Syntax:

Guid str2Guid(str text)
 

24.str2Int64 Function:

Converts a string into an Int64 value.

Syntax:

int str2Int64(str text)
 
Example:
    str myStr;
    str tooBig;
    Int64 myInt64;
    ;
   
    myStr = "1234567890";
    tooBig = int642str(int64Max()+1);
   
    myInt64 = str2Int64(mystr);
    info (strfmt ("int64: %1",myInt64));
   
    myInt64 = str2Int64(tooBig);
   info(strfmt ("Too big int64: %1",myInt64));
Op: int64: 1234567890
    Too big int64: -9223372036854775808


25.str2Num Function:

Converts a string to a real number.

Syntax: real str2Num(str _text)
Example:
    str s="12.45";
    real r;
    r=str2Num(s);
    info(s);
Op:12.45
  

26.str2Time Function:

Converts a string to a timeOfDay value.

Syntax: int str2Time(str _text)

Note:The number of seconds between midnight and the _text parameter; otherwise, -1.

Example:

    int i;
    i=str2time("2:31");
    print i;
    pause;
Op: 9060

27.time2Str Function:

Converts a timeOfDay value to a string that includes hours, minutes, and seconds.

Syntax:

str time2Str(
    int _time,
    int _separator,
    int _timeFormat)

Example:

timeOfDay theTime = timeNow();
    ;
    info( time2Str(theTime, TimeSeparator::Colon, TimeFormat::AMPM) );

 

Op: 06:22:37 pm

28. uint2Str Function:

Converts an integer to a string with the assumption that the integer is unsigned.

Syntax:

str uint2Str(int integer)z
Example: info(int2str(3123456789));  //-1171510507


Export a copy of the standard user acceptance testing (UAT) database

 Reference link: Export a copy of the standard user acceptance testing (UAT) database - Finance & Operations | Dynamics 365 | Microsoft ...