Change Default Settings for Notifications

Hey everyone,

I have managed to write a Loading Script which changes 2 of the default settings when “Sharing”/extracting data into an Excel file (namely - automatically Freeze Header Rows for excel, AND automatically append the date to the file name) which is great as the majority of my users would manually do this themselves.

Should anyone wish to use it the Loading script is below…

However I can’t seem to recreate the same rules for a user setting up a notification? I have scoured through the Script Documentation and can’t find anything specific that would point me in the direction of the user interface, although I am guessing this may be due to the fact that under Notification Content the options seem to be parameters not a UI.

Could anyone suggest how I update the below script so that if a User is setting up a Notification that these would default as “ticked”.

On a secondary note - is there anyway to update all dashboards and reports globally with such a script? Once I had created the below, I had the most tedious task of going through each dashboard and updating the loading script, which is just tiresome…any hints on that would be a life saver before I fall to sleep at my desk :stuck_out_tongue:

Thank you as always:

var exportService = dundas.context.getService(“ExportService”);
var viewService = dundas.context.getService(“ViewService”)
var getUI = exportService.getCustomConfigurationUI;
exportService.getCustomConfigurationUI = function(providerId){
$(viewService.currentDialogShown).bind(dundas.controls.ExportDialogConstants.loadUICompletedEventName, function() {
$("#" + dundas.constants.APPEND_DATE_TO_FILE_NAME_ID.toUpperCase(), dundas.context.currentDialogShown.contents)[0].checked = true;
})
$(viewService.currentDialogShown).bind(dundas.controls.ExportDialogConstants.loadUICompletedEventName, function() {
$("#" + dundas.constants.EXCEL_FREEZE_HEADER_ROWS.toUpperCase(), dundas.context.currentDialogShown.contents)[0].checked = true;
})
return getUI.apply(this, arguments);
}

Hey Chris,

In V9 we introduced a better event to hook up to to allow you to do this cleaner. If you want to change this across the application you can create add the following to the Javascript Override (Admin->Setup->App Styling)

Here’s a template script for you (It handles both the Notification Content dialog and the Export dialog and has stubs there for each of the default export providers:

$(document).ready(function() {
    window.dundas.context.ready(function() {      
      
      var handleProviderChange = function (providerId) {
          // Excel
          if (providerId == dundas.constants.STANDARD_EXCEL_EXPORT_PROVIDER_ID) {
              //$('#' + dundas.constants.EXCEL_EXPORT_SELECTION_ID.toUpperCase()).val(dundas.export.ExportSelection.MULTIPLE_ITEMS).trigger("change");
              //$('#' + dundas.constants.EXCEL_ADAPTERS_ID.toUpperCase()).val("<visualization adapter ID(s)>");
              //$('#' + dundas.constants.EXCEL_INCLUDE_PARAMETERS_ID.toUpperCase()).prop("checked", true);
              //$('#' + dundas.constants.EXCEL_FREEZE_HEADER_ROWS.toUpperCase()).prop("checked", true);
              //$('#' + dundas.constants.EXCEL_SORTABLE_DATES.toUpperCase()).prop("checked", false);
          }
          // PDF
          else if (providerId == dundas.constants.STANDARD_PDF_EXPORT_PROVIDER_ID) {
              //$('#' + dundas.constants.PDF_ORIENTATION_ID.toUpperCase()).val(dundas.print.PaperOrientation.LANDSCAPE);
              //$('#' + dundas.constants.PDF_LEFT_MARGIN_ID.toUpperCase()).val(0.7);
              //$('#' + dundas.constants.PDF_RIGHT_MARGIN_ID.toUpperCase()).val(0.7);
              //$('#' + dundas.constants.PDF_TOP_MARGIN_ID.toUpperCase()).val(0.5);
              //$('#' + dundas.constants.PDF_BOTTOM_MARGIN_ID.toUpperCase()).val(0.5);
          }
          else if (providerId == dundas.constants.STANDARD_IMAGE_EXPORT_PROVIDER_ID) {
              //$('#' + dundas.constants.PNG_EXPORT_SELECTION_ID.toUpperCase()).val(dundas.export.ExportSelection.SINGLE_ITEM).trigger("change");
              //$('#' + dundas.constants.PNG_ADAPTER_ID.toUpperCase()).val("<visualization adapter ID>");
          }
          // CSV
          else if (providerId == dundas.constants.STANDARD_CSV_EXPORT_PROVIDER_ID) {
              //$('#' + dundas.constants.CSV_ADAPTER_ID.toUpperCase()).val("<visualization adapter ID>");
          }
          // PPT
          else if (providerId == dundas.constants.STANDARD_POWERPOINT_EXPORT_PROVIDER_ID) {
          }
      }

      var viewService = dundas.context.getService("ViewService");
      $(viewService).bind(viewService.constants.DialogShownEventName, function () {
          // Bind to export dialog opening
          if (this.currentDialogShown.contents[0].id == dundas.controls.ExportDialogConstants.dialogId) {
              var providerSelect = $(this.currentDialogShown.contents).find(dundas.controls.ExportDialogConstants.providerListId);
              $(this.currentDialogShown).bind(dundas.controls.ExportDialogConstants.providerReadyEventName, function () {
                  handleProviderChange(providerSelect.val());
              });
          }
          // Bind to notification dialog opening
          if (this.currentDialogShown.contents[0].id == dundas.controls.NotificationContentDialogConstants.notificationContentDialog) {
              var providerSelect = $(this.currentDialogShown.contents).find(dundas.controls.NotificationContentDialogConstants.selectExportProvider);
              $(this.currentDialogShown).bind(dundas.controls.NotificationContentDialogConstants.providerReadyEventName, function () {
                  handleProviderChange(providerSelect.val());
              });
          }
      });
   });
});
1 Like

Hi Kevin,
Thanks for sending this - just going from the point of

Will this script only work in V9?

I have inserted the script into the JavaScript resource JSOverride and removed the relevant // to activate the stubs but when then testing on a report where I have not entered a Ready Script the changes were not initiated :frowning:

I can see what you have written so trying to tweak it now so that it kicks in - or maybe I am missing a step - I will continue to tweak and try something to get it to kick in.

Thanks

Hi Chris,

The event ‘providerReadyEventName’ which is what was added in V9 is what makes this all work. It’s not there in V8 or earlier and that’s why I started my original post with that disclaimer.