Runtime components : Client engine : Using the client engine : Programming with the client engine
  
Programming with the client engine
Establish session with BTT server
// See Session.establish() for details
BTT.establishSession(function(store){
console.debug(store);
alert("establishSession : success");
}, function(respone){
console.debug(response);
alert("establishSession : fail");
});

// Execute a stand-alone operation.
// Please refer to Engine. execOperation() for details
BTT.execOperation("ChangeAliasOp",
{"UserData":{"alias":"abc"}},
function(store){
console.debug(store);
alert("execOperation: success");
}, function(respone){
console.debug(response);
alert("execOperation: fail");
}
).done(function(){
alert("execOperation");
});


// Launch a new flow.
// Please refer to Engine.launchFlow() for details
var flow = BTT.launchFlow("TransferFlow", null,
function(store){
console.debug(store);
alert("launchFlow: success");
}, function(respone){
console.debug(response);
alert("launchFlow: fail");
}
);

// get the name of the flow instance
console.log("flow name:", flow.getName());
// get the current state name of the flow instance
console.log("flow state:", flow.getState());
// get the store binding to this flow instance
var store = flow.getStore();
console.log("flow store:", store);

/**
* Submit the user input to server (flow), and then fire the exit event of
* the current User State.
* The flow will be transited to the next state as the specified event name.
* This method validates the input data automatically at
* the beginning of its execution. If the validation fails, it calls
* the error call-back function, and then returns false.
*/
// For more information, see Flow.changeEvent ()
var isOK = flow.changeEvent("transfer", {
Amount : 123,
fromAccountNO : "001",
toAccountNO : "002"
}, function(store, flow){
console.debug(store);
alert("changEvent:", flow.getName(), flow.getState());
}, function(response, flow, errorFields){
if (errorFields) // validation error
{
console.debug(errorFields);
alert("changeEvent: validation error");
}else{
console.debug(response);
alert("changeEvent: fail");
}
});


/**
* Execute an operation under flow (context).
* The context of this operation is chained under
* the flow context, which means it can access its own operation context,
* its parent flow context, its parent session context and
* the application(root) context.
* This method validates the input data automatically at
* the beginning of its execution. If the validation fails, it calls
* the error call-back function, and then returns false.
*/
// For more information, see Flow.execOperation ()
flow.execOperation("CheckBalanceOp", {
AccountNO : "001"
}, function(store, flow){
console.debug(store);
alert("execOperation:", flow.getName(), flow.getState());
}, function(response, flow, errorFields){
if (errorFields) // validation error
{
console.debug(errorFields);
alert("execOperation: validation error");
}else{
console.debug(response);
alert("execOperation: fail");
}
});


// Destroy the session and disconnect with BTT server
// For more information, see Session.destroy()
BTT.destroySession(function(response){
console.debug(response);
alert("destroySession: success");
}, function(respone){
console.debug(response);
alert("destroySession: fail");
});
See also:
Go up to
Using the client engine