validateWrite method and canBeConverted.

Hi,

I need to do some validation on a field to check if the a unit ID can be converted or not (i.e if a conversion exsists or not).

So far I have this:

public boolean validateWrite()

{

boolean ret;

if (ret == UnitOfMeasureConverter::canBeConverted(UnitOfMeasure::findBySymbol(lwPurchLineTable.PurchUnit).RecId,

UnitOfMeasure::findBySymbol(InventTable::find(lwPurchLineTable.ItemId).inventUnitId()).RecId, NoYes::Yes))

{

ret = super();

}

else

{

warning(“can not convert”);

}

return ret;

}

but It seems to always get to the warning even though the conversions exists. I have tested with both existing and non existing conversions.

Hi

eeehhhmmm… what did you mean with this statement (?):

You declared a variable which gets an initial value as FALSE. And then immediately you compare this variable with a value returned by canBeConverted() function… In other words, if the canBeConverted() function would return a postive result, then your comparison looks like this:

IF (FALSE == TRUE)) // which will never happen, if conversion does exist

{

}

Janis

I see, but in that case if we change it to:

if(UnitOfMeasureConverter::canBeConverted)

and as a result the canBeConverted() returns true then it should work correctly. Except it doesnt. This is the pseudo code for what I need it to do.

if (conversion exists)

super();

else

info(" it doesnt exists")

This is how your code is supposed to look like:

public boolean validateWrite()
{
boolean ret;
;

ret = super(); // first do system validations, if everyting was ok (i.e., all mandatory fields filled etc.), then proceed…

// if there were no system validation problems, then start with custom validations
if(ret && UnitOfMeasureConverter::canBeConverted(…))
{
ret = true;
}

return ret;
}

If this does not work, then you are passing wrong values to conversion validation function…

Janis

And please, do not hesitate to use debugger. You could have debugged the problem in 5 minutes.

Still cant get it to work, Like you said I guess its something wrong with the wrong values in. Thanks for your help.