I created a new grid in the projtable form with the LOB field and Proeject id ,percentage in a separate table.Here for each project we add a multiple lob with the percentage value. Here i need to validate sum of percentage field for each project should not be greater than 100 . So while the user adds the percentage for a project with different LOB and if the percentage exeeds beyond 100 then it should not allow the user to save it…Please help me with a sample method and which place should i write exactly. Please let me know if the description is not clear.
you should override validateWrite or validateField methods depending on the requirement and check the sum(percentage), throw an error if it exceeds 100. validateWrite will be triggered during the record save and validateField after entering a value in percentage field.
select sum(percentage) from yourTable; (use common field from the projTable and yourTable in the where clause)
And one more important thing.Current record is not inserted.System will not consider your current record percentage.You need to add current record percentage with select statement.Please find the below code.Hope it will be helpful.
public boolean validateWrite()
{
boolean ret;
CaeProjlob caeprojlob1;
ProjTable projtable1;
Real total;
ret = super();
if (ret)
{
select sum(percentage) from caeprojlob1 where caeprojlob1.ProjId == this.ProjId;
total = caeprojlob1.Percentage + this.Percentage;
if (total > 100)
{
ret = ret && checkFailed(“Sum of the percentage per project cannot be more than 100%”);
}
}
return ret;
}
If i add 1st line with 99 and 2nd line with 2 is not accepting.Thats correct logic.But after i delete 2nd line and modify the 1st line as 100 , it was throwing validation error instead saving the same.Might be it doesnt allow me to modify.