To restrict values to be entered in a field

Hi,

I need to restrict the user not to subscribe more than 4 books:

I done it using as following method:

public boolean aosValidateInsert()
{
boolean ret;
AX_SubscriberMaster axsm;
AX_TransactionHeader axt;
AX_TransactionLine axtl;
;
ret = super();
select count(recId) from axtl where axtl.Trans_Id == this.Trans_Id;
if(axtl.recId > 3)
ret = checkFailed(“User can’t subscriber more than 4 books”);
return ret;
}

wat dis method doing is after I entered the 5th value it showing warning.
So I want to make the table from entering the 5th value.

How can I do tat?
Thanks.

You can override the create method on form data source and call the validation.

can you give me code?

I need to restrict the form to enter 5th value in the line

What do you mean by enter in AX terms? (create, modify etc…)

may be below link can help you

jkmsdax2012.wordpress.com/…/

I done it using validatewrite method as:

public boolean validateWrite()
{
boolean ret;
AX_SubscriberMaster axsm;
AX_TransactionHeader axt;
AX_TransactionLine axtl;
;
ret = super();
select count(recId) from axtl where axtl.Trans_Id == this.Trans_Id;
if(axtl.recId > 3)
ret = checkFailed(“User can’t subscriber more than 4 books”);
return ret;
}