您可以使用 JavaScript 開發驗證命令檔,以用於驗證分析條件和資料欄公式,並且封鎖無效的查詢。
使用分析的使用者可以呼叫自訂 JavaScript,驗證分析條件和資料欄公式。驗證能夠讓您在編輯分析時封鎖查詢。自訂 JavaScript 必須可透過 Web 伺服器存取。若要啟用此功能,管理員需在系統設定值中指定 Web 伺服器的 URL,並將該 Web 伺服器註冊為安全網域。
每當使用者嘗試執行分析時,Oracle Analytics 都會呼叫 validateAnalysisCriteria
函數。您可以自訂 validateAnalysisCriteria
以根據自己的特定條件來驗證與封鎖查詢。如果函數傳回 true
,則會執行查詢。如果函數傳回 false
或顯示訊息,則會封鎖查詢。
例如,下列簡單的 JavaScript 程式碼名為 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; }
如果函數傳回 false
以外的任何結果,則會將條件視為有效並且執行分析。此函數同時會用於驗證預覽與儲存作業的條件。
每當使用者嘗試輸入或修改資料欄公式,Oracle Analytics 就會呼叫 validateAnalysisFormula
函數來驗證該作業。您可以自訂 validateAnalysisFormula
,依自己的特定條件驗證和封鎖公式。若函數傳回 true
,公式會被接受。若驗證失敗,函數會傳回 false
,該公式會被拒絕並顯示您的自訂訊息。
若要顯示訊息並允許使用者繼續,您的函數必須傳回 true
。若要封鎖查詢,您的函數必須傳回 false
或顯示訊息。您可以在函數中使用 JavaScript 字串和正規表示式技術來調查和驗證公式。
查詢封鎖函數可使用協助程式函數檢查篩選、資料欄等。請參閱驗證協助程式函數。
例如,下列程式碼顯示若使用者輸入不被接受的公式時,要如何封鎖該查詢。
// This is a formula blocking function. It makes sure the user doesn't enter an unacceptable formula. function validateAnalysisFormula(sFormula, sAggRule) { // don't allow the use of concat || in our formulas var concatRe = /\|\|/gi; var nConcat = sFormula.search(concatRe); if (nConcat >= 0) return "You used concatenation (character position " + nConcat + "). That isn't allowed."; // no case statements var caseRe = /CASE.+END/gi; if (sFormula.search(caseRe) >= 0) return "Don't use a case statement."; // Check for a function syntax: aggrule(formula) aggrule shouldn't contain a '.' var castRe = /^\s*\w+\s*\(.+\)\s*$/gi; if (sFormula.search(castRe) >= 0) return "Don't use a function syntax such as RANK() or SUM()."; return true; }
JavaScript 檔案提供多種驗證協助程式函數供您使用。
驗證協助程式函數 | 描述 |
---|---|
|
傳回分析參照的主題區域名稱。通常會在執行其他驗證前,將它用於函數內的 switch 敘述句中。若分析為集合式條件,則會傳回 |
|
若內容設計人員已將指定的資料夾 (表格) 新增至分析,會傳回 |
|
若內容設計人員已將指定的資料欄新增至分析,會傳回 |
|
若有 |
|
若指定資料欄中有篩選,會傳回 |
|
若輸出清單中有 |
|
傳回對指定邏輯資料欄指定的篩選值數目。若篩選值為 " |