Validate Range.

Hi All,

I have one table with three fields Code, fromWeight and toWeight.

I want a validation in order to prevent overlapping of fromWeight and Toweight range.

Please Help.

hello moumita

Why dont you use validateField method.

Hi kumar,

Since the validation depends on two field , so validate field will not work properly.

I have used validate write as follows :

public boolean validateWrite()
{
boolean ret;

NIM_ItemWeightBucket ItemWtBucket1,ItemWtBucket2,ItemWtBucket3,ItemWtBucket4,ItemWtBucket5;
real i,j,k;
;

ret=true;
if(this.Symbol=="")
{

ret=checkFailed(“Set default Unit ID in invent parameter”);
}
else
{
while select ItemWtBucket1
{
for(i=this.FromWeight;i<=this.ToWeight;i=i+0.01)
{
j=ItemWtBucket1.FromWeight;
select count(RecId) from ItemWtBucket2 where (ItemWtBucket2.FromWeight==i || ItemWtBucket2.ToWeight==i);
if(ItemWtBucket2.RecId>0)
{
if(k==0)
{
ret=checkFailed("This range already exists/ Range overlaping not allowed ");
k++;
}
break;
}

}
}
}

return ret;
}

But it may not be correct way to solve the purpose, so that I have asked you all if any one could give me a right solution.

Hello Das

check below code it will use to you.

public boolean validateField(fieldId _fieldIdToCheck)
{
boolean ret;

ret = super(_fieldIdToCheck);

switch (_fieldIdToCheck)
{
case fieldNum(tutorial_Form_DynaLink2 [tablename],field2 [fieldname]):
if (this.Field2<this.Field1)
ret = checkFailed("@GLS62531");
break;
}

return ret;
}

If issue was toweight not less than fromweight

Hi Moumita,

I hope the following code will solve ur issue in a simple way. Write this code in validateWrite method of the table.

select minof(fromWeight), maxof(toWeight) from tableName where tableName.RecId != this.RecId;

if (this.low < tableName.fromWeight && this.high < tableName.fromWeight)

{

ret = true;

}

else if (this.low > tableName.toWeight&& this.high > tableName.toWeight)

{

ret = true;

}

else

{

ret = checkFailed(“Values overlapping”);

}

replace this.low and this.high by this.fromWeight and this.toWeight…

Hi Faisal Raja,

Now it’s working fine. Thanks a lot.

Welcome [:)]