Need filter to default to first available value

Hello, I am trying to set up a filter that can only show 1 lead at a time (no ‘all’ option), but I do not know how to set the parameter so that it’s not a specific lead by default, but whoever is first in the list. Defaulting to a specific lead’s name will cause issues in the future if that employee moves or quits, so it needs to be dynamic, but it won’t be the user.

Hi Lindsey,

Scripting isn’t my strong suit but I’d imagine you could setup a custom script token to filter based on whoever is first in the list.

2 Likes

As a follow up, to get this to work, a metric set with only the lead names needs to be added to the dashboard (not visible), optionally filtered to the dates desired (keeping in mind this won’t update as users change the date, which was fine for me as I just wanted a lead to show initially).

Then the following script needed to be added to the Ready actions on the dashboard (the console.log()s aren’t necessary but can be uncommented to check results if there are issues), replacing the desired parameter name and metric set id of the hidden metric set:

// In a view's (e.g., dashboard's) ready or load actions, use this rather than this.parentView:
var view = this;
var viewParameter = view.control.getViewParameterByName("Lead Parameter");

// Remove all values and tokens from the parameter value
viewParameter.parameterValue.clearTokens();
viewParameter.parameterValue.clearValues();

// Time dimensions have a little bit more going on, so in this example
// we will be pulling the member value from an existing metric set,
// and just to make it interesting, we will use a data retrieval service
// to get the metric set data

// The metric set ID, which can be found in the edit dialog from the Data Analysis Panel
var metricSetId = "a4bc660c-781c-47ba-a179-a638aa8a7670";

// Get the DataRetrievalService
var dataRetrievalService = this.getService("DataRetrievalService");
var viewService = this.getService("ViewService");

// Create a request object using the metric set ID
var request = new dundas.data.Request({
"objectId": metricSetId,
"requestData": dundas.Utility.createGuid(),
});

// Call getData from the service and wait for it to finish using its deferred object
var def = dataRetrievalService.getData(request);

// Show a loading message if the response takes some time
// viewService.showLoadingRestCall(def);

// When we have the data, run the following
def.done(function (dataResults) {
// Here we load the first member from the first row of the data result
//console.log(dataResults[0].cellset)
  var memberValue = dataResults[0].cellset.rows[0].members[0].loadMemberValue();
	//console.log(memberValue);

viewParameter.parameterValue.values[0] = memberValue;

// Set the last modified time so this parameter takes precedence over any others
viewParameter.invalidateParameterValueLastModifiedTime();

// Update all the connected adapters with the newly modified values
// Includes data visualizations and filter controls
// Pass the current view in case it's embedded in another
viewParameter.refreshAllAdapters();
});
//console.log(viewParameter);
2 Likes