Problem
Depending on a selected value of a field, other fields should be editable / not be editable.
In this case the requirements are:
- The object shall be editable, when no other Attribute with the description „Variant Status“ has the text (or the selection in case of enum) „Proposal“
- The object shall be not ediablte, when one of Attribute with the description „Variant Status“ is set to „Proposal“
- Exception: The field, that contains a set „Proposal“ Value, shall be editable in each case, otherwise it would not be possible to leave that state
Approach – Ansatz
The following codes installs an Object-Trigger (not attribute), that is fired every time a user double-clicks our is entering an object, but only when the module is in edit mode;
Solution – Lösung
string DXLCode = "
Trigger trg = current;
if (null trg) halt();
AttrDef ad = attrdef(trg);
if (null ad) halt(); // Error?
Object obj = object(trg);
if (null obj) halt(); // Error?
string Name = ad.name;
Module mod = module(trg);
if(!isEdit(mod)) halt();
Object oCurr = current(mod);
string thisFieldShouldBeEditable = \"n/a\";
bool hasProposal = false;
int i=0;
for ad in mod do
{
if(ad.object)
{
if(ad.description \"\" == \"Variant Status\")
{
string BB_Variant_name=ad.name;
if(obj.BB_Variant_name \"\" == \"Proposal\")
{
hasProposal=true;
thisFieldShouldBeEditable=BB_Variant_name;
}
}
}
}
bool thisIsTheProposalField=false;
if(Name==thisFieldShouldBeEditable)
{
thisIsTheProposalField=true;
}
// Wenn kein Attribut auf Proposal steht oder das angeklickte Feld
// das Proposal Feld ist, brauchen wir nix mehr machen
if(!hasProposal||thisIsTheProposalField) halt();
// Wenn ein Attribut auf Proposal steht soll er blockieren
// Der nachfolgende Text text verhindert dass das Edit-Event zu Ende gebracht wird
set(trigPreConFail);
if (isVisible(mod) and obj == oCurr)
{
infoBox(\"The field \" thisFieldShouldBeEditable \" is set to proposal.");
}
else{}
" // End definition of string DXLCode
Trigger trg;
bool TrigOK = true;
string ErrMess = checkDXL(DXLCode);
if (!null ErrMess)
{
print ErrMess "\n***********\n" DXLCode "**********\n"
TrigOK = false
}
string NameTrig = "TriggerResetValidatedOn"
string Prompt = "Delete trigger '" NameTrig "' ??"
if (!TrigOK) Prompt = "Trigger code has errors.\n" Prompt
if (confirm(Prompt))
{
ErrMess = delete (NameTrig, module->object, pre, open, 6);
}
if (TrigOK && confirm("Deploy trigger '" NameTrig "' ??"))
{
trg = trigger(NameTrig, module->object, pre, open, 6, DXLCode)
}