Wednesday, April 2, 2014

Dynamics AX Sorting Container

static void SR_sortContainer(Args _args)
{
container con = [5,1,2,'Sumit Loya',9, 'Ashish singh', NoYes::No];
str temp1;
str temp2;
int i;
int j;
container sorCon;
;
sorCon = con;
// Sort the container
for (i = 1; i <= conlen(sorCon); i++)
{
for (j = i + 1; j <= conlen(sorCon); j++)
{
temp1 = conpeek(sorCon, j);
temp2 = conpeek(sorCon, i);
if (temp1 < temp2)
{
sorCon = condel(sorCon, j, 1);
sorCon = conins(sorCon, j, temp2);
sorCon = condel(sorCon, i, 1);
sorCon = conins(sorCon, i, temp1);
}
}
}
conview(sorCon);
}

Only foreign key constraints are allowed on this table - How to rectify this best practice error.

This Best practice error comes when we create a normal relation. so for that create an index for the field on which you want to create a relation, and set theAlternateKey property of the index to "Yes". Now go to this table properties and set the PrimaryIndex property to the newly created index.Now when you create a foreign key based relation on the child table it will automatically create a relationship on the field that you have set as the PrimaryIndex. so in this way you can create a normal relation through foreign key relation and you can get rid of this Best practice error.
eg.
Table1 -> Field1,Field12
Index1 -> Field1 having AlternateKey set to "Yes".
Table1 -> properties->PrimaryIndex set to "Index1".
Table2 -> create a foreign key relation (Foreign key -> Primary key based)
then automatically a reation Table2.Table1 ==Table1.Field1 is created.
In this way you can easily create a relation on any field other than RecId. and also the BP error Only foreign key constraints are allowed on this table will remove.