Changes

JavaScript - Limiting Outcomes

2,089 bytes added, 21:12, 8 September 2014
no edit summary
This articles explains the fundamentals of manipulating the outcomes through JavaScript.
 
 
== Elements ==
 
 
The outcomes are always in the drop down list labelled named strContact_Outcome. This field is a standard select type.
 
 
The outcomes values are the data value of the outcome rather than an Id, to help with custom manipulation of data. This does however require greater care at matching the text of the outcome is done. If an outcome text does not match a CCL and the associated processes will not be performed.
 
 
== Support Functions ==
 
 
There are a number of library functions within the page to help your manipulations.
 
* function fn_BE_BlankOutcomes()
* function fn_BE_AddOutcome( strText, strValue )
* function fn_BE_ResetOutcomes()
 
 
 
== General advised approach ==
 
 
The general advised approach when modifying the outcome list is to wipe the options and then to reintroduce the options you need.
 
 
So fn_BE_BlankOutcomes() will wipe all the options in there first.
 
 
You then should add back in the options using fn_BE_AddOutcome. Please note that the strText and strValue, must match your existing system outcomes EXACTLY for processing to happen!
 
 
 
== Resetting ==
 
 
If in doubt about how to return the outcome list to as it was with no manipulation from your side, you can use the fn_BE_ResetOutcomes to reset the outcome list before any custom modifications. This is a useful default position to return the list to a workable state.
 
 
 
== Worked example ==
 
 
So if you had conditions to limit the contents the function should look similar to
 
 
<syntaxhighlight lang="javascript">
 
function fn_ModifyOutcomes(){
 
// First we empty the outcomes
fn_BE_BlankOutcomes();
//Now your conditions
if (condition1 == true) {
fn_BE_AddOutcome( 'Outcome1', 'Outcome1' );
}
else if (condition2 == true) {
fn_BE_AddOutcome( 'Outcome2', 'Outcome2' );
}
else {
// And a safety net if your conditions are not true
// No outcomes and the record cannot be saved
fn_BE_ResetOutcomes();
}
}
 
</syntaxhighlight>
 
This function would be put into the onLoad of the form and called on the onChange of drop down lists or other content bearing items.
7,528
edits