Develop JavaScript to Block Analyses Based on Criteria
Whenever a user tries to run an analysis, Oracle Analytics invokes the
function validateAnalysisCriteria. You can customize
validateAnalysisCriteria to validate and block queries based on your
own specific criteria. If the function returns true, the query runs. If
the function returns false or displays a message, the query is
blocked.
For example, the following is sample code for a JavaScript program called
myblocking.js.
// This is a blocking function. It ensures that users select what
// the designer wants them to.
function validateAnalysisCriteria(analysisXml)
{
// Create the helper object
var tValidator = new CriteriaValidator(analysisXml);
// Validation Logic
if (tValidator.getSubjectArea() != "Sample Sales")
return "Try Sample Sales?";
if (!tValidator.dependentColumnExists("Markets","Region","Markets","District"))
{
// If validation script notifies user, then return false
alert("Region and District are well suited, do you think?");
return false;
}
if (!tValidator.dependentColumnExists("Sales Measures","","Periods","Year"))
return "You selected a measure so pick Year!";
if (!tValidator.filterExists("Sales Measures","Dollars"))
return "Maybe filter on Dollars?";
if (!tValidator.dependentFilterExists("Markets","Market","Markets"))
return "Since you are showing specific Markets, filter the markets.";
var n = tValidator.filterCount("Markets","Region");
if ((n <= 0) || (n > 3))
return "Select 3 or fewer specific Regions";
return true;
}
If the function returns anything other than false, the criteria is
considered to be valid and the analysis runs. The function is also use to validate
criteria for preview and save operations.