Adding Custom Confirmation to Toolbar Items

Back To Blog

I’m normally against custom code in Clarity templates and reports.  Too many times I’ve seen consultants build code rather than find a way to satisfy the requirements using existing base functionality.  This makes templates & reports harder to maintain and difficult for clients to figure out after the implementation team is gone.  This was especially true in Clarity 6 where the code was always hidden on the server.

That said, there are  times when custom coding is the only option available to build required advanced functionality – and thanks to power exposed in Clarity 7 we can now maintain that code within the Studio Advanced tab.

Clarity has standard confirmation (Are you sure?) messages boxes when saving or retrieving – but what if you want to display a message when a function is complete?  Or better yet, add a confirmation box before the function is run!  In this blog entry I will show you, with only 1 line of code, how you can add a confirmation box to any toolbox menu item.

  • Step 1 – Open any existing template or report in Studio and navigate to the Advanced tab.  Select Browser Jobs and add a new VBScript job called ‘vbsConfirm’.
  • Step 2- In the Script area enter the following statement:

If MsgBox(“Are you sure?”,4,”Confirm”)  = 7 Then CLARITY.template.cancelEvent = true

Be sure to enter this all on 1 line without any <Enter> presses.  If you are not familiar with the VBS MsgBox function you can review the available options at the following website:

This is the most important part of the process.  Notice that if the MsgBox returns a 7 ( = No) that we abort the Clarity call by setting the CLARITY.template.cancelEvent property = true.  This will cause Clarity to abort the function after the custom code in the “Before Tool” section is complete.

  • Step 3 – Add a new VBScript job called ‘vbsCompleted’.
  • Step 4 – In the Script area enter the following statement:

MsgBox “Function Completed”

  • Step 5 – In the Tool Events, right click and select “Open In Excel “.

This of course could be any item, but for our example we’ll be adding a confirmation button to the Open in Excel functionality.  If you do not see this option feel free to select another or add this item in the Features -> Tools area of Studio.

  • Step 6 – You will see your 2 browser jobs in the Available Jobs area.  Add vbsConfirm to the “Before Tool” area and vbsCompleted to the “After Tool” area.

  • Step 7 – Save and Run the Template / Report.

When you select ‘Export to Excel’ you will now receive a message box requesting confirmation of the action.

If you answer “No” the function aborts.  If you answer “Yes” the function will run and when it’s done you will receive a completion message.

Feel free to play around with the wording and logic for your own requirements.

As always, let me know if you have any problems with this or wan to discuss other custom functionality you are looking to add to your Clarity solution.