문제

I have tableA (fields: playerId, skill)

So my question is: how to make so that user can not add more than 5 same playerId?

Table's which method to override and what to do?

Tanks...

도움이 되었습니까?

해결책

You can create a new integer field AttributeNum. You can override the insert() or the initValue() on the table depending on you requirement. Choose initValue() over insert() if you would like to keep your set-based operation fast on this table.

In the overriden method you can use query to aggregate and count the number of attributes per your current record.

Edit:

Alternately you can just override the validateWrite() method on the table.

boolean validateWrite()
{
    TableA        tableA;
    boolean       ret = super();    
    #define.MaxAttributes(5) // consider using setup         
    if (ret && !this.RecId)
    {
        select count(RecId) from tableA where tableA.PlayerId == this.PlayerId;    
        if (tableA.RecId >= #MaxAttributes)
        {    
            ret = checkFailed("Error message goes here");
        }    
    }
    return ret;
}

You didn't specify if the attributes should be unique per player or not but you should also consider creating the appropriate index in order to enforce data integrity.

You can find more information here:

Maintain Fast SQL Operations [AX 2012]

Speeding Up SQL Operations [AX 2012]

Maintaining Data Integrity [AX 2012]

Data Model for New Microsoft Dynamics AX Modules [AX 2012]

Where to Place the Code [AX 2012]

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top