AnsweredAssumed Answered

Ensure associated fields contain data if primary field set to specific value

Question asked by silvermane on May 31, 2016
Latest reply on Jun 14, 2016 by keywords

On my layout I have a field that if the value is set to "YES" then 2 other fields MUST contain data.  If the primary field is set to "NO" then the associated fields MUST be empty.

Basically, I don't want the user to be able to leave the layout unless the above rules apply.

The script below which I have tried triggering at various stages sort of works but the user can still 'break' it and allow the rules to be broken.

A simpler, more elegant solution would be appreciated.

 

#This script adds a comment and date & time timestamp separator in the notes field

Set Variable [ $$Reqdfields; Value:If ( Main CBC Database::Financial = "Yes" ; Case ( IsEmpty ( Main CBC Database::DateSubsPaid ) ; "Empty" ; IsEmpty ( Main CBC Database::HowSubsPaid ) ; "Empty" ; "ok" ) ; "ok" ) ]

If [ $$Reqdfields = "Empty" ]

Show Custom Dialog [ Title: "Invalid Data"; Message: "Cannot have empty fields if member is checked as financial.¶Please insert Date of Payment and/or Method of Payment."; Default Button: “OK”, Commit: “Yes”; Button 2: “Cancel”, Commit: “No” ]

Loop

If [ IsEmpty ( Main CBC Database::DateSubsPaid ) ]

Go to Field [ Main CBC Database::DateSubsPaid ]

Else If [ IsEmpty ( Main CBC Database::HowSubsPaid ) ]

Go to Field [ Main CBC Database::HowSubsPaid ]

End If

Set Variable [ $$Reqdfields; Value:If ( Main CBC Database::Financial = "Yes" ; Case ( IsEmpty ( Main CBC Database::DateSubsPaid ) ; "Empty" ; IsEmpty ( Main CBC Database::HowSubsPaid ) ; "Empty" ; "ok" ) ; "ok" ) ]

Pause/Resume Script [ Indefinitely ]

Exit Loop If [ $$Reqdfields = "ok" ]

End Loop

#Insert Note

Set Selection [ Main CBC Database::notes; Start Position0; End Position0 ]

Insert Calculated Result [ "Subscription paid on " & Main CBC Database::DateSubsPaid & " by " & Main CBC Database::HowSubsPaid ] [ Select ]

Set Selection [ Main CBC Database::notes; Start Position0; End Position0 ]

Insert Calculated Result [ "--- " & Get(CurrentDate) & " @ " & Get(CurrentTime) & " by " & Get(AccountName) & " ---¶" ]

End If

If [ Main CBC Database::Financial = "No" ]

Set Field By Name [ Main CBC Database::DateSubsPaid; Main CBC Database::DateSubsPaid = "" ]

Set Field By Name [ Main CBC Database::HowSubsPaid; Main CBC Database::HowSubsPaid = "" ]

End If

Exit Script [ ]

Outcomes