People Goal 5 - Part 6: Add a custom dialog

Document created by Kedar on Feb 4, 2015Last modified by communitymanager on May 12, 2015
Version 13Show Document
  • View in full screen mode

 


At this point your script works fine for deleting portal rows, but the message in the confirmation dialog could be confusing for your users. Right now it asks, “Permanently delete this one related record?” If your users don’t understand what a related record is, they might not know how to respond and could worry that they aren’t making the right decision.

 

Let’s make the confirmation message more user-friendly. This will involve adding a custom dialog to your delete script. With custom dialogs, you get to specify what the dialog will say, including the title, the message, and button text for up to three different buttons that capture the user’s response. In this case, you just need to change the phrase “this one related record” to something that describes your secondary table data more clearly, such as “this activity” or “this enrollment”.

 

You’ll also use the special function “Get(LastMessageChoice)”. This function returns a numeric value indicating which of the three possible buttons the user chose in response to your custom dialog. Here are the possible values returned by the function:


1 = Default button

2 = Button 2

3 = Button 3

When you’re done with this script, it should resemble “Delete portal row” in the example solution.


 

Goal:

 

To improve the confirmation dialog in your “Delete portal row” script.

 

 

Steps:

 

Try it without a dialog

 

  1. Choose the Scripts menu > Script Workspace…  ⇧⌘S or Ctrl S

  2. Select your "Delete portal row” script in the left panel to open it.

  3. Select the Delete Portal Row step in your script.

  4. Click the gear icon to view the script step options.


  5. Select the Perform without dialog option.
    delete portal row options.png

  6. Save the script by typing ⌘S (Mac) or Ctrl-S (Windows) but leave the script open.

  7. As before, create a new row in your portal, entering some data to identify it.

  8. Click your trashcan button to run your script.

    The portal row is deleted automatically, with no dialog beforehand to confirm the action.


Try it with a custom dialog


  1. Return to your open script in the Script Manager.

  2. Add a Show Custom Dialog script step as the second line of your script.

  3. Drag it upwards (above the Delete Portal Row step) to make it the first line of your script.

  4. Click the gear icon to specify the script step options.

    A Show Custom Dialog Options window appears.

  5. Enter a title for your custom dialog: Delete [Secondary Tablename]

    The example solution uses "Delete Activity".


  6. Enter a message for your custom dialog that is specific to your solution.

    Your message should refer to the content of your secondary table. The example solution has the message “Do you want to permanently delete this activity?"

  7. Change the Default Button text to “Cancel”.

  8. Change the Button 2 text to “Delete”.

  9. Click the OK button to dismiss the dialog window.


    Although your custom dialog is complete, right now it will have no effect on what the script does. Regardless of the user’s response, the script will go ahead and delete the portal row.

    What is missing is a way for the script to make a decision based on the user’s response. For this, you’ll use the same script steps as before: If and End If.

  10. Add an If script step below the Show Custom Dialog script step.

    Two script steps are added, If and End If.

  11. Drag the Delete Portal Row step upwards so that it is between the If and End If steps.

  12. Select your If script step and click the fx button.

    A Specify Calculation dialog window appears.

  13. Enter the expression:  Get ( LastMessageChoice ) = 2, then click the OK button to close the dialog window.

    If the user selects button 2, then the above expression evaluates as true. Otherwise it evaluates as false.

    Because the Delete Portal Row script step is enclosed by the If and End If, it is performed only when the user selects Button 2, which you labeled as “Delete”.

    Your script is now complete. It should look like this:
    pasted-image-9.png


  14. Close your script, saving your changes when prompted.


Test your custom dialog


  1. Once more, create a new row in your portal, entering some data to identify it.

  2. Click the trashcan to run your script.

    You should see a confirmation dialog similar to this:
    pasted-image-10.png

  3. Choose the “Cancel” button and confirm that nothing happens.

  4. Choose the “Delete” button and confirm that the portal row is deleted.

      

      

Attachments

    Outcomes