ValidateField () fires every time the user changes the value in a field. The methods parameters give you the fieldId.
An Example of ValidateField() on a table in axapta is :
public boolean validateField(fieldId _fieldIdToCheck)
{
boolean ret;
;
ret = super(_fieldIdToCheck);
Switch (_fieldIdToCheck)
{
Case fieldNum(MyTable,CustName) :
if(strlen(this.CustName) < =3)
ret = checkFailed("Customer Name must be longer than 3 characters");
break;
Case fieldNum(MyTable,PhoneNumber):
------//Validation Condition for this field//--------
break;
}
return ret;
}
ValidateWrite() Executed when a record is written to the database, before the data change is committed in the database(wen you save a record on a form).Used to check whether all mandatory fields are filled or not.
Example :
An Example of ValidateField() on a table in axapta is :
public boolean validateField(fieldId _fieldIdToCheck)
{
boolean ret;
;
ret = super(_fieldIdToCheck);
Switch (_fieldIdToCheck)
{
Case fieldNum(MyTable,CustName) :
if(strlen(this.CustName) < =3)
ret = checkFailed("Customer Name must be longer than 3 characters");
break;
Case fieldNum(MyTable,PhoneNumber):
------//Validation Condition for this field//--------
break;
}
return ret;
}
ValidateWrite() Executed when a record is written to the database, before the data change is committed in the database(wen you save a record on a form).Used to check whether all mandatory fields are filled or not.
Example :
public boolean validateWrite()
{
boolean ret;
;
ret = super();
if
(!this.EstimatedArrivalDate)
{
infolog.add(Exception::Warning,StrFmt("@SYS116347",fieldid2pname(tableNum(JSS_ProjBudgetTable),fieldNum(JSS_ProjBudgetTable,EstimatedArrivalDate))));
ret = ret && false;
}
if (!this.EstimatedDepartureDate)
{
infolog.add(Exception::Warning,StrFmt("@SYS116347",fieldid2pname(tableNum(JSS_ProjBudgetTable),fieldNum(JSS_ProjBudgetTable,EstimatedDepartureDate))));
ret = ret && false;
}
if
(this.EstimatedArrivalDate > this.EstimatedDepartureDate)
{
infolog.add(Exception::Warning,StrFmt("@SYS113171"));
ret = ret
&& false;
}
return ret;
}
initValue() This method file while creating new record to initialize a value, here I am assigning user id to the userID field.
public void initValue()
{
super();
this.UserId = curuserid();
}
public void initValue()
{
super();
this.UserId = curuserid();
}
ValidateDelete() While deleting a record if we want to put any validation we can use this method. Here once I delete a record populating a info for that deleted record.
public boolean validateDelete()
{
boolean ret;
ret = super();
info(this.AccountNum);
return ret;
}
{
boolean ret;
ret = super();
info(this.AccountNum);
return ret;
}
ModifiedField()
This method will execute if modified a record value, this works based on the field value.
Here I am using to fill the name field value according to the AccountNum
public void modifiedField(fieldId _fieldId)
{
CustTable ct;
;
super(_fieldId);
switch(_fieldId)
{
case fieldNum(Cust_new,AccountNum) :
{
this.Name = CustTable::find(this.AccountNum).Name;
}
break;
}
}
This method will execute if modified a record value, this works based on the field value.
Here I am using to fill the name field value according to the AccountNum
public void modifiedField(fieldId _fieldId)
{
CustTable ct;
;
super(_fieldId);
switch(_fieldId)
{
case fieldNum(Cust_new,AccountNum) :
{
this.Name = CustTable::find(this.AccountNum).Name;
}
break;
}
}
Happy Daxing :)
No comments:
Post a Comment