Initializing help system before first use

Modifying Scenario Data

The JavaScript API provides a way of requesting a set of changes to scenario input data and applying those changes on the server.
The changes are expressed as a list of changes to be applied in the specified order then they are committed to the server for processing. If any of these changes fail to be applied they will all be rolled back and nothing will be modified. Upon completion the server will either respond as successful or if a failure occurs it will provide an error message and status code.
Note Changes to scenario data are not applied to the scenario object within a particular invocation of a scenario observer. When a scenario observer is called it is passed immutable scenario data.
The key features of scenario data modification are:
  • Batched: Changes are created as a batch request and committed to the server as one request.
  • Atomic: All changes are applied as an atomic operation on the server.
  • Transactional: If an error is encountered while applying the changes everything will be rolled back.
  • Asynchronous: When changes are sent to the server, a Promise is returned which either will be resolved or rejected based on the server response.
  • Ordered: The order in which you specify the changes is the order in which they are applied on the server.
  • Scenario-oriented: Each batch request is applied to a specific scenario.
  • Applied server-side: Changes are not applied to any existing scenario objects in your view. The changes will not be available until scenario observers update themselves.

To request changes to scenario data, you first need to create a ScenarioDataChange object for a specific scenario. This can be created in two ways:

From a scenario observer
view.withFirstScenario()
   .withEntities('SCALAR1', 'ARRAY1')
   .notify(function(scenario) {
       // Create a ScenarioDataChange object for 
       // the first scenario
       var changes = scenario.modify();
   })
   .start();
Outside a scenario observer
// Create a new ScenarioDataChange object for the first scenario.
// The number argument is the selection index of the scenario
var changes = view.modifyScenario(0);

The first approach is more convenient if you are already using a scenario observer. Also there is a subtle difference in the way change events are propagated around your view with these two approaches. See the next section for more details.

The ScenarioDataChange object offers a chainable API (each call returns the ScenarioDataChange instance) to express your changes and then commit them. When the changes are committed a Promise is returned so you can detect and respond to success or failure.
scenario.modify()
   .setScalar('SCALAR1', 55)
   .addToSet('SET1', [15, 16, 17])
   .setArrayElement('ARRAY1', {key: [15], value: 'fifteen'})
   .removeFromSet('SET1', [16, 17])
   .commit()
   .then(function() {
       // Applied successfully
   })
   .catch(function(error) {
       // Error applying changes
       // Server rolled back any partial changes
       console.log('Could not apply changes, reason: ' +
           error.message +', status code: ' + error.status);
   });

The JavaScript API documentation lists all the available methods on ScenarioDataChange.

Because the changes are applied in order you can add elements to a set and then reference those keys in arrays index by that set. If you add array elements and then remove the set elements corresponding to the keys the array element will end up never existing in the scenario data.

© 2001-2020 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.