Wednesday, January 28, 2015

Enable/Disable swapable logic

Switching between Disabled and Enabled fields function


I needed to set several fields to disabled or enabled based on a status field. To do this in people code was easy enough using the field DERIVED_REC.EXT_ORG_ID.Enabled = False and DERIVED_REC.EXT_ORG_ID.DisplayOnly = True to disable. However to enabled I'd have to repeat that code with the opposite values. Often this switching is necessary in several places so I built this way of making the change in a function.

Example

I put the function in the first field FieldFormula of the record. Then you simple declare you function where you need it and call it with a boolean value.

Declare Function allowEditFields PeopleCode DERIVED_REC.EMPLID FieldFormula;
allowEditFields( True);
  1. Function allowEditFields(&ENABLE);
  2. Local boolean &enabled;
  3. Local boolean &displayOnly;
  4. If &ENABLE Then;
  5. &enabled = True;
  6. &displayOnly = False;
  7. Else
  8. &enabled = False;
  9. &displayOnly = True;
  10. End-If;
  11. DERIVED_REC.STRM.Enabled = &enabled;
  12. DERIVED_REC.STRM.DisplayOnly = &displayOnly;
  13. DERIVED_REC.EXT_ORG_ID.Enabled = &enabled;
  14. DERIVED_REC.EXT_ORG_ID.DisplayOnly = &displayOnly;
  15. DERIVED_REC.MCM_TR_TO_DT.Enabled = &enabled;
  16. DERIVED_REC.MCM_TR_TO_DT.DisplayOnly = &displayOnly;
  17. DERIVED_REC.MCM_TR_FROM_DT.Enabled = &enabled;
  18. DERIVED_REC.MCM_TR_FROM_DT.DisplayOnly = &displayOnly;
  19. DERIVED_REC.MCM_TR_PROG.Enabled = &enabled;
  20. DERIVED_REC.MCM_TR_PROG.DisplayOnly = &displayOnly;
  21. DERIVED_REC.MCM_TR_PREV_ATD.Enabled = &enabled;
  22. DERIVED_REC.MCM_TR_PREV_ATD.DisplayOnly = &displayOnly;
  23. DERIVED_REC.MCM_TR_STDNT_ID.Enabled = &enabled;
  24. DERIVED_REC.MCM_TR_STDNT_ID.DisplayOnly = &displayOnly;
  25. DERIVED_REC.ADD_PB.Enabled = &enabled;
  26. DERIVED_REC.UPDATE_PB.Enabled = &enabled;
  27. DERIVED_REC.PRINT_BTN.Enabled = &enabled;
  28. End-Function;