2 Replies Latest reply on Sep 17, 2015 10:29 AM by greengk2fi

    Nested If w/ Custom Dialog

    greengk2fi

      I've created a basic script for deleting a client so I could offer two different warnings about deleting clients. The script first determines whether or not a client has services/sales associated with it. If the client does not, the user receives a simple warning saying the deletion cannot be undone. The user can choose to Delete or Cancel.  If the client has services, the user receives a bit more of a warning telling them that they shouldn't delete a client with services unless the record is a training dummy.

       

      The script works perfectly for clients without services, the appropriate warning appears and cancelling cancels the script and deleting deletes the active client and then shows all clients. The script begins to work for the second case for clients with services/sales. The appropriate warning appears; but deletes the client record whether or not the user selects Cancel or Delete. I've looked at the script for a long time trying to find a problem in matching Ifs or responses. I can find none unless the second instance of getting the button response needs a different integer rather than [ Get (LastMessageChoice) = 1 ] . The full script is below. Any help is appreciated.


       

      DeleteClient

      Set Variable [ $CurrentClient; Value:tblClient::_pkClientID ] Go to Object [ Object Name: "All Services" ]
      Enter Find Mode [ ]
      Set Field [ tblClient::_pkClientID; $CurrentClient ]

      Set Field [ tblService::ServiceDate; "*" ] Set Error Capture [ On ]
      Perform Find [ ]
      If [ Get(FoundCount) = 0 ]

      Enter Find Mode [ ]

      Set Field [ tblClient::_pkClientID; $CurrentClient ]

      Perform Find [ ]

      Show Custom Dialog [ Title: "Permanently Delete?"; Message: "Deleting a client cannot be undone. To keep this client's record select Cancel. To delete this client select Delete."; Default Button: “Delete”, Commit: “Yes”; Button 2: “Cancel”, Commit: “No” ]

      If [ Get (LastMessageChoice) = 1 ] Delete Record/Request

      [ No dialog ] Show All Records

      Go to Object [ Object Name: "Client Information" ] Else

      Exit Script [ ] End If

      Else

       

          

       

      Show Custom Dialog [ Title: "Deleting Client Data Cannot Be Undone"; Message: "This client has service records. If you delete this client, you will lose not only his or her information; but all of their services and associated records.¶¶Deleting a client with services should be avoided unless it is a fictional client you have used for training.¶¶To keep this client, select cancel. To delete this client permanently, select Delete"; Default Button: “Delete Client”, Commit: “Yes”; Button 2: “Cancel”, Commit: “No” ]

      Delete Record/Request

      [ No dialog ]
      If [ Get (LastMessageChoice) = 1 ]

      Delete Record/Request
      Show All Records
      Go to Object
      [ Object Name: "Client Information" ]

      Else
      Exit Script
      [ ]

       

       

      End If End If

       

        • 1. Re: Nested If w/ Custom Dialog
          erolst

          Your problem stems from a Delete Record following directly after a Show Custom Dialog!

           

          Please be so kind and post-process your code after pasting it here; you can see there are lots of odd line break. Also, while beautifying the script and adding indentation, you're forced to think about the script logic – which is a great chance to spot flaws.

           

          In this case, your problem stems from a Delete Record following directly after a Show Custom Dialog!

           

          btw, you can simplify this script enormously – all that's different in both sections are the dialog box texts; also, from a Client context, an easy way to determine if the client has services is to see if there is at least one related Services record:

          not IsEmpty ( Service::id )

           

          So …

           

          Set Variable [ $hasServices ; not IsEmpty ( Service::id ) ]

           

          Set Variable [ $title ; Case ( $hasServices ;

          "Delete Client Data Cannot Be Undone" ;

          "Permanently Delete." ) ]


          Set Variable [ $message ; Case ( $hasServices ;

          "This client has service records. If you delete this client, you will lose not only his or her information; but all of their services and associated records.¶¶Deleting a client with services should be avoided unless it is a fictional client you have used for training.¶¶To keep this client, select cancel. To delete this client permanently, select Delete" ;

          "Deleting a client cannot be undone. To keep this client's record select Cancel. To delete this client select Delete." ) ]


          Show Custom Dialog [ Title: $title; Message: $message; Default Button: “Delete Client”, Commit: “Yes”; Button 2: “Cancel”, Commit: “No” ]


          If [ Get (LastMessageChoice) = 1 ]

            Delete Record/Request [ No dialog ]

            Show All Records

            Go to Object [ Object Name: "Client Information" ]

          Else

            Exit Script [ ]

          End If

          • 2. Re: Nested If w/ Custom Dialog
            greengk2fi

            O my god!  Thank you for saving me from my own idiocy. Clearly too much time at one time in front of the screen. Good suggestions also for simplifying and also cleaning up the post. Thanks again.