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.
To improve the confirmation dialog in your “Delete portal row” script.
Try it without a dialog
- Choose the Scripts menu > Script Workspace… ⇧⌘S or Ctrl S
- Select your "Delete portal row” script in the left panel to open it.
- Select the Delete Portal Row step in your script.
- Click the gear icon to view the script step options.
- Select the Perform without dialog option.
- Save the script by typing ⌘S (Mac) or Ctrl-S (Windows) but leave the script open.
- As before, create a new row in your portal, entering some data to identify it.
- 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
- Return to your open script in the Script Manager.
- Add a Show Custom Dialog script step as the second line of your script.
- Drag it upwards (above the Delete Portal Row step) to make it the first line of your script.
- Click the gear icon to specify the script step options.
A Show Custom Dialog Options window appears.
- Enter a title for your custom dialog: Delete [Secondary Tablename]
The example solution uses "Delete Activity".
- 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?"
- Change the Default Button text to “Cancel”.
- Change the Button 2 text to “Delete”.
- 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.
- Add an If script step below the Show Custom Dialog script step.
Two script steps are added, If and End If.
- Drag the Delete Portal Row step upwards so that it is between the If and End If steps.
- Select your If script step and click the fx button.
A Specify Calculation dialog window appears.
- 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:
- Close your script, saving your changes when prompted.
Test your custom dialog
- Once more, create a new row in your portal, entering some data to identify it.
- Click the trashcan to run your script.
You should see a confirmation dialog similar to this:
- Choose the “Cancel” button and confirm that nothing happens.
- Choose the “Delete” button and confirm that the portal row is deleted.