Just a Word of Caution: The example that we are going to try today would affect all your edit box prompts. Just use caution and modify the below example according to your needs.
The example that we are going to try today is to add some simple validation criterion to the edit box in the Dashboard Prompt i.e. allow users to enter only numeric values. If they enter anything else then pop up an error message asking them to try again (without refreshing the whole page). This example deals with modifying the underlying Java Scripts. The steps are as follows
1. Go to {OracleBI}\web\app\res\b_mozilla\prompts. There you would find a file called as globalfilterprompt.js. All the methods that make the dashboard prompts work are present in this file.
2. Now open this file in a text editor and search for GFPBuildFilter(). This is the function that builds the filter for Dashboard Prompt. Replace this function with the one below.
function GFPBuildFilter()
{
var tExpr = XUICreateElement(saw.xml.kSawxNamespace, ‘expr’);var tArgs = GFPBuildFilter.arguments;
var tF = new GFPQueryFilter(tArgs[0],tArgs[1]);var tSQLExpr = XUICreateElement(saw.xml.kSawxNamespace, ‘expr’);
tSQLExpr.setAttribute(“xsi:type”, “sawx:sqlExpression”);
XUISetElementText(tSQLExpr, tArgs[0]);
tExpr.appendChild(tSQLExpr);var bNoVal = true;
var sNewOp = tF.sOp;// MBH6 shows some errors where GFP still has eq for some reason. Most surgical fix
// is to uncomment this check.
if (sNewOp == “eq”)
sNewOp = “in”;if (sNewOp == “bet”)
sNewOp = “between”;var sType = tArgs[2];var tValues = new Array();
if (sType == “multi”)
tValues = GFPParseArgs(tArgs)
else
{
for (var i = 5; i < tArgs.length; ++i)
{
tValues[tValues.length] = GFPRightTrim(tArgs[i]);
}
}// is a variable to be set?
var sSetVariable = tArgs[4];//convert datetime; sTimeZoneOffset is ’0′ if data type is not datetime or type is ‘drop’
var sTimeZoneOffset = tArgs[3];
var nOffset = parseInt(sTimeZoneOffset)
if (nOffset)
{
var tDTP = new DateTimeParser();
for (var i = 0; i < tValues.length; ++i)
{
tValues[i] = saw.tz.parseAndAdjustTimeZoneOffset(tValues[i], nOffset);
}
}// if more arguments, then values
for (var i = 0; i < tValues.length; ++i)
{
var sVal = tValues[i];if ((sVal == ksDropDownNone || !sVal) && sNewOp != “between”) //if sVal is empty, it is consider the value is not specified. We should not change the operator to NULL in this case.
return;
else if ((sVal == ksDropDownNone || !sVal) && sNewOp == “between”)
continue;
else if ((sVal == ksDropDownAllChoices || sVal == ksEditBoxAllChoices) && sNewOp == “between”)
{
//treat all choices in between op as blank but always apply the filter
bNoVal = false;
continue;
}if (sVal == “(All Choices)”)
sVal = ksDropDownAllChoices;// check for null or just whitespace
/*if (sVal == ksDropDownUnspecified)
{
sNewOp = “ignore”;
bNoVal = false;
}*/if (sType == “edit” && sVal != “”)
{
var validation = /^[0-9]+$/;
if (!sVal.match(validation))
{
alert(“Only Numbers Allowed Here”);
return;
}
}if (sType == “edit” && sVal == “”)
return;// if all choices
else if ((sVal == ksDropDownAllChoices) || (sVal == ksEditBoxAllChoices))
{
sNewOp = “prompted”;
bNoVal = false;
break;
}// if null
else if (sVal == ksDropDownNull || !sVal)
{
sNewOp = “null”;
bNoVal = false;
}// if they specified a value
else if (sVal != null && (sVal.search(/^\s*$/) == -1))
{
bNoVal = false;
// check for operators we allow user to override
if (sType == “edit” && ((tF.sOp == “in”) || (tF.sOp ==”like”)))
{
// Check for operator
if (sVal.search(/^=/) != -1)
{
sNewOp = “in”
sVal = sVal.replace(/^=\s*/,”");
}
else if (sVal.search(/^/) != -1)
{
sNewOp = “notIn”;
sVal = sVal.replace(/^\s*/,”");
}
else if (sVal.search(/^<=/) != -1)
{
sNewOp = “lessOrEqual”;
sVal = sVal.replace(/^=/) != -1)
{
sNewOp = “greaterOrEqual”;
sVal = sVal.replace(/^>=\s*/,”");
}
else if (sVal.search(/^</) != -1)
{
sNewOp = “less”;
sVal = sVal.replace(/^/) != -1)
{
sNewOp = “greater”;
sVal = sVal.replace(/^>\s*/,”");
}
}
tF.AddPredArg(tExpr, sVal);}
}if (bNoVal)
{
// JPR 8/05 – this check is causing problems with between since it was forcing to prompted.
// We can’t determine why this sType != “drop” was ever necessary, so we’re returning in
// all cases when there is no value
// if (sType != “drop”)
return;// JPR 8/05 – the comment below makes no sense to us, assuming old logic and returning above now
// Change to prompt as ignore prevents users from blanking out an entry.
//tF.sOp = “prompted”;
//sNewOp = “prompted”;
}/* if (tF.sOp == “in” && tF.vValues.length == 1)
sNewOp = “equal”;
*/
if (tF.sOp == “cany”)
sNewOp = “containsAny”;
if (tF.sOp == “call”)
sNewOp = “containsAll”;
if (tF.sOp == “bwith”)
sNewOp = “beginsWith”;
if (tF.sOp == “ewith”)
sNewOp = “endsWith”;// between must have two values
if (sNewOp == “between”)
{
var sVal = tValues[0];
var sVal2 = tValues[1];// var bVal = (sVal && (sVal != ksDropDownAllChoices) && (sVal != ksEditBoxAllChoices));
// var bVal = (sVal2 && (sVal2 != ksDropDownAllChoices) && (sVal2 != ksEditBoxAllChoices));
if (sVal == ksDropDownAllChoices || sVal == ksEditBoxAllChoices || sVal == ksDropDownNone)
sVal = “”;if (sVal2 == ksDropDownAllChoices || sVal2 == ksEditBoxAllChoices || sVal2 == ksDropDownNone)
sVal2 = “”;if (!(sVal && sVal2))
{
if (!sVal && sVal2)
tF.sOp = “lessOrEqual”;
else if (sVal && !sVal2)
tF.sOp = “greaterOrEqual”;
else
tF.sOp = “prompted”;
}
}
else
tF.sOp = sNewOp;GFPGetOpType(tExpr, tF.sOp);
//tExpr.setAttribute(“xsi:type”, sType);
tExpr.setAttribute(“op”, tF.sOp);if (null != sSetVariable && sSetVariable != “”)
XUISetAttributeString(tExpr, “setVariable”, sSetVariable);return tExpr;
}
The code that we have added extra to the actual function is the one below
if (sType == “edit” && sVal != “”)
{
var validation = /^[0-9]+$/;
if (!sVal.match(validation))
{
alert(“Only Numbers Allowed Here”);
return;
}
}
What this does is, it checks whether we are calling this from the Edit box. If yes, then we make the validation of “Only Numbers are Allowed here”. Then save this file.
3. Copy this file to {OracleBI}\oc4j_bi\j2ee\home\applications\analytics\analytics\res\b_mozilla\prompts i.e we need to overwrite the globalfilterprompt.js that is present in this directory so that both the java scripts are in sync.
4. Restart the presentation services and OC4J. Now if you enter some characters in the dashboard prompt it will throw an error.
Remember this will affect all your dashboard prompts. You would have to add more conditions to narrow it down to a single edit box in a particular page. This would give you an idea of how to modify the underlying Java Scripts.