I have a condition where field A = Bank or field B = Bank then field C mandatory(true).
i use the validateWrite method but got stuck when i want to set the field to mandatory.
[ExtensionOf(tableStr(LedgerJournalTrans))]
final class LedgerJournalTrans_TOC_ValidasiOffsetAccTypeBank_Extension
{
public boolean validateWrite()
{
boolean ret;
LedgerJournalTrans ledgerJournalTrans;
LedgerJournalTable ledgerJournalTable;
FormDataObject obj;
;
ret = next validateWrite();
if(this.OffsetAccountType == LedgerJournalACType::Bank || this.AccountType == LedgerJournalACType::Bank)
{
ret = checkFailed("You Must Input Bank Transaction Type");
}
return ret;
}
}
can someone help me with this?
First of all, let me simplify your code a bit:
[ExtensionOf(tableStr(LedgerJournalTrans))]
final class LedgerJournalTrans_TOC_ValidasiOffsetAccTypeBank_Extension
{
public boolean validateWrite()
{
boolean ok = next validateWrite();
if (this.AccountType == LedgerJournalACType::Bank
|| this.OffsetAccountType == LedgerJournalACType::Bank)
{
ok = checkFailed("You Must Input Bank Transaction Type");
}
return ok;
}
}
Your requirement is to check if field C is filled in, so you can add that condition. Like this:
public boolean validateWrite()
{
boolean ok = next validateWrite();
if (this.AccountType == LedgerJournalACType::Bank
|| this.OffsetAccountType == LedgerJournalACType::Bank)
{
if (!this.FieldC)
{
ok = checkFailed(...);
}
}
return ok;
}
Or you can combine it in a single condition:
public boolean validateWrite()
{
boolean ok = next validateWrite();
if (!this.FieldC
&& ( this.AccountType == LedgerJournalACType::Bank
|| this.OffsetAccountType == LedgerJournalACType::Bank))
{
ok = checkFailed(...);
}
return ok;
}
I see Martin, but can you give me an example after checkFailed field C turn into mandatory.
I use this.BankTransType.mandatory(true) and it doesn’t work.
btw Field C is BankTransType
There is no such a thing. this.BankTransType is an enum, i.e. a number, and it has no mandatory() method. The purpose of validateWrite() method is checking conditions and returning false if validations fail (together with adding explanation to infolog). It has nothing to do with any mandatory() method.
Where you can use mandatory() is in forms, namely form data source fields and form controls. This will show users that a control is considered mandatory. You can use active() method (or the corresponding event) of a form data source to do something when a record activated in a form. In your case, you can check if your condition is met and set mandatory() of the field to true or false.
For example:
boolean fieldCMandatory = ledgerJournalTrans.AccountType == LedgerJournalACType::Bank
|| this.OffsetAccountType == LedgerJournalACType::Bank);
this.object(fieldNum(LedgerJournalTrans, FieldC)).mandatory(fieldCMandatory);
okay Martin, now my code is like this.
[extensionof(formdatasourceStr(LedgerJournalTransVendPaym, LedgerJournalTrans))]
final class TOC_LedgerJournalTransVendPaym_DS_Extension
{
public boolean validateWrite()
{
LedgerJournalTrans ledgerJournalTrans;
boolean ret = next validateWrite();
FormStringControl BankTransType = this.formRun().design().controlName("BankTransType") as FormStringControl;
if ( !BankTransType.valueStr())
{
ret = checkFailed("You Must Input Bank Transaction Type");
this.object(fieldNum(LedgerJournalTrans, BankTransType)).mandatory(true);
}
return ret;
}
}
This works fine but now how to set my validation inside the if?
the validation is ledgerJournalTrans.AccountType == LedgerJournalACType::Bank
// || this.OffsetAccountType == LedgerJournalACType::Bank
That’s not what I said at all. Could you read my previous reply once more, please?
ooh oke Martin, thank you