Alfasith AX

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

Monday, February 22, 2021

How to achieve table relation in SQL without primary index 1:n

HI,

Select particular parent table (master table) db.table.
1. Right click select design

2. Select the respective field where we have to achieve unique index but not primary.
Right click on that filed select Indexs/keys...



3. Add the select the column to from that list and please make sure you change the property to YES in isUnique.


4. Save and select the design of transaction table where we try to achive Foreign key.
Right click on that particular filed and choose Relationships..


5. Add the relationship by select the tables and columns specifics.




Regards,

 

Thursday, February 18, 2021

RandomNumbers In AX /D365

 Hi,


static void CreateRandomNumbersInAX(Args _args)

{

    RandomGenerate randomGenerate;

    ;

    randomGenerate = RandomGenerate::construct();

    randomGenerate.parmSeed(new Random().nextInt());

    info(int2str(RandomGenerate.randomInt(0,2147483647)));   //RandomInt(RangeFrom,RangeTo)

    //Note: Range from should be more than natural number 0 and more.

 

}

OutPut

1786303728


To understand the formula behind this random number please refer randomInt() in RandomGenerate class.

The formula in randomNumber generation is not similar to library function of dotnet.

Note: We cannot treat this randomGenerated Values as primary key, this may repeat with same range.

Regards,



GUID in AX 2012 / D365

 //< What is GUID>

// GUID 16 bit large range of alphanumeric similar to RecID to treat as primary key of a table.

static void CreateGUIDInAX(Args _args)

    str 60 strGuid;

    ;

    info(Winapi::createGUID());         // Creates GUID and removes the braces

    info(guid2str(newGuid()));           // Creates GUID with braces

    //NOTE: GUID is not a string so we needs to convert GUID to str for using...

}

Output:

C2B4FEBF-2393-43BB-9EA5-B173B907CA2A

{BAD14349-5837-4AC3-9B9B-9D6FB0F86BEC}

note: Your output and mine needs to be same.


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) ...