Previous Topic: JavaScript Business Logic Task HandlersNext Topic: IMSAPI Class References


JavaScript Method Reference

A JavaScript handler implements the same methods as the Java BLTHAdapter class:

handleStart(BLTHContext ctx)
handleSetSubject(BLTHContext ctx)
handleValidation(BLTHContext ctx)
handleSubmission(BLTHContext ctx)

Example:

// This sample illustrates BLTH implemented in java script
// It verifies that a tag specified in the task is unique in 
// the environment function 

handleValidation(blthContext, errorMsg) {
    var taskTag = null;
    var currentTask = blthContext.getAdminTask();
    if(currentTask != null) {
        taskTag = blthContext.getAdminTask().getTaskTag();
    }

    if(taskTag == null) {
        errorMsg.reference = "Failed to get the task tag";
        return false;
    }
    try {
        task = blthContext.getAdminTaskProvider().findByTag(taskTag);
    } catch(exception) {
        // there is no task with this tag
        return true;
    }

    if (!currentTask.equals(task)) {
        errorMsg.reference = "Tag must be unique: " + taskTag;
        return false;
    } else {
        // the same task
    }

    return true;
}