Step 2 – Adding function mappings to your scenario

Next, we’ll add a function mapping to your scenario, to define what functions from your model are involved, and what corresponding JScript methods will handle data processing for those functions.

The next evolution of our GetScenarios method should look like this, with the highlighted text showing what has been added.

class Scenario {

  var make_request = { func: "Make Request", method: "Customer.MakeRequest" };
  var receive_request = { func: "Receive Request", method: "Sales.ReceiveRequest" };

  function GetScenarios(params) {

    var result = {};

    result["scenarios"] = [
      {
        name: "Enquiry",
        description: "Customer inquires about products",
        mapping: [
          make_request,
          receive_request
        ]
      }
    ];

    return result;
  }
}

You’ll notice a few things have been added.

We’ve added 2 function mappings at the top, called make_request and receive_request.

These are JScript variables which specify how your scripts are related to AIM functions.

  • The func attribute MUST EXACTLY MATCH the name of the function in your AIM model, and it is case-sensitive.
  • The method attribute MUST EXACTLY MATCH one of your JScript functions.

Once the variables make_request and receive_request are defined, they need to be added in to your scenario, within the mapping element as follows:

result["scenarios"] = [
  {
    name: "Enquiry",
    description: "Customer inquires about products",
    mapping: [
      make_request,
      receive_request
    ]
  }
];

The reason that we defined the make_request and receive_request variables separately, rather than inline within the mapping attribute is that if we’re going to define lots of scenarios we don’t want to have to constantly redefine MakeRequest and ReceiveRequest.

Using this approach, we can reuse the make_request and receive_request variables in each new scenario that we define as required.

This will become clearer in this tutorial as we build out one scenario, and then create an overlapping scenario using the same scripting building blocks.

Once you’ve saved your .js file containing this updated GetScenarios method, you can then switch back into AIM to see the progress so far.

In AIM, click the Scenarios tab along the top menu.

You should see a Enquiry scenario panel in the top left.

If you click on the panel (not the play button), you should see something like the following, where the Make Request and Receive Request functions are highlighted, as per the mapping that you just saved.

Any changes saved to .js files are reloaded by AIM when you click on the Scenarios tab, and so incrementally building and reviewing scenarios is a fairly fast process.

If you click the play button on the Enquiry scenario panel, you’ll see a message “AIM Server found. Simulation started”, however the simulation will then stop, because the Customer.MakeRequest method has not yet been defined in your scripts.

We’ll do this next…Creating business scenario scripts