Callback not working in the FileTracker functions

Status: fixed in 2.0.3.3

You might have noticed that when using the ecm/model/FileTracker class in IBM Content Navigator, the callback is never called.

For instance if you are using the following code:

FileTracker.downloadAndTrackFiles(documentInfoObj, function (response) {
    console.log("Never invoked");
});

the callback is never called. This is because there is a defect in the FileTracker processMessage function, it does not look correctly for the callback because of a = missing in the condition:

var callbackResponse;
if (response.responses && response.responses.length > 0) {
	var callbackResponse;
	for ( var i = 0; i < response.responses.length; i++) {
		if (response.responses[i].errorCode = this.SERVER_RESPONSE_CALLBACK) {
			callbackResponse = response.responses[i];
			break;
		}
	}
} else if (response.errorCode == this.SERVER_RESPONSE_CALLBACK) {
	callbackResponse = response;
}

This is fixed in Fix Pack 3 though (2.0.3.3), so you can either upgrade or use a plugin to do an aspect around and replace the function by the correct one, which is:

processMessage: function(json, showSuccessMessage) {
	var methodName = "processMessage";
	this.logEntry(methodName);

	var response = dojojson.fromJson(json);
	if (response.hasError) {
		var errorPrefix = "", inserts = [];
		var showError = true;
		if (response.errorCode == 7) {//ERROR_OPEN_FAILED
			errorPrefix = "runtime_file_tracking_file_not_found_error";
		} else if (response.errorCode == 3) {
			errorPrefix = "runtime_file_tracking_ioexception_error";
		} else if (response.errorCode == this.ERROR_NOT_TRACKED) {
			showError = false;
		} else if (response.errorCode == this.ERROR_OPEN_FAILED) {
			showError = true;
			errorPrefix = "runtime_file_tracking_open_error";

		} else if (response.errorCode == this.ERROR_SAVE_FILE_FAILED) {
			showError = true;
			errorPrefix = "runtime_file_tracking_save_file_error";

		} else if (response.errorCode == this.ERROR_SAVE_FILE_FAILED_AND_OPEN_FIALED) {
			showError = true;
			errorPrefix = "runtime_file_tracking_save_file_after_checkout_error";

		} else if (response.errorCode == this.ERROR_ENVIRONMENT_VARIABLE_PATH_NOT_FOUND) {
			showError = true;
			errorPrefix = "runtime_file_tracking_ev_file_path_not_found_error";

		} else if (response.errorCode == this.ERROR_OPEN_CONNECTION) {
			showError = true;
			errorPrefix = "runtime_file_tracking_ioexception_error";

		} else if (response.errorCode == this.ERROR_FOLDER_NOT_FOUND) {
			showError = true;
			errorPrefix = "runtime_file_tracking_exact_file_path_not_found_error";

		} else if (response.errorCode == this.ERROR_EXACT_PATH_NOT_FOUND) {
			showError = true;
			errorPrefix = "runtime_file_tracking_exact_file_path_not_found_error";

		} else if (response.errorCode == this.ERROR_CANNOT_CREATE_TRACKING) {
			showError = false;
			errorPrefix = "runtime_file_tracking_exact_file_path_not_found_error";

		} else if (response.errorCode == this.ERROR_DELETE_FILE_FAILED) {
			showError = true;
			errorPrefix = "runtime_file_tracking_cannot_delete_file_error";

		} else {
			showError = true;
			errorPrefix = "runtime_file_tracking_generic_error";
		}

		if (showError) {
			if (response.responses && response.responses[0].value) {
				inserts.push(response.responses[0].value);
			} else if (response.value) {
				inserts.push(response.value);
			}
			Desktop.addMessage(Message.createErrorMessage(errorPrefix, inserts, false));
		}

	} else {
		var successMessage = "";
		if (response.responses) {

			if (response.responses.length == 1 && ((response.responses[0].errorCode == this.ERROR_DELETE_FILE_FAILED || response.responses[0].errorCode == this.FOUND_TRACKED_RECORD_BY_FILE_PATH) || (response.responses[0].errorCode == this.FOUND_TRACKED_RECORD_BY_SCANNING) || (response.responses[0].errorCode == this.SUCCESSFULLY_TRACKED_FILE_USING_ADS))) {

				successMessage = string.substitute(ecm.messages.file_tracking_successfully_downloaded_document, [
					response.responses[0].originalDocumentName,
					response.responses[0].value
				]);
			} else if (response.responses.length > 1 && ((response.responses[0].errorCode == this.FOUND_TRACKED_RECORD_BY_FILE_PATH) || (response.responses[0].errorCode == this.FOUND_TRACKED_RECORD_BY_SCANNING) || (response.responses[0].errorCode == this.SUCCESSFULLY_TRACKED_FILE_USING_UD) || (response.responses[0].errorCode == this.SUCCESSFULLY_TRACKED_FILE_USING_ADS))) {

				var count = response.responses.length;
				var documentsDownloaded = [];
				for ( var i = 0; i < count; i++) {
					documentsDownloaded.push(response.responses[i].originalDocumentName);
				}
				successMessage = string.substitute(ecm.messages.file_tracking_successfully_downloaded_document, [
					documentsDownloaded.join(",")
				]);

			}
		}

		if (successMessage && successMessage.length > 0) {
			Desktop.addMessage(new Message({
				number: 0,
				level: 0,
				text: successMessage
			}));
		}

		var callbackResponse;
		if (response.responses && response.responses.length > 0) {
			var callbackResponse;
			for ( var i = 0; i < response.responses.length; i++) {
				if (response.responses[i].errorCode == this.SERVER_RESPONSE_CALLBACK) {
					callbackResponse = response.responses[i];
					break;
				}
			}
		} else if (response.errorCode == this.SERVER_RESPONSE_CALLBACK) {
			callbackResponse = response;
		}
		if (callbackResponse && callbackResponse.value) {
			var lookupId = callbackResponse.value.callbackId;
			if (lookupId && this.callbackMap[lookupId]) {
				var callbackFunc = this.callbackMap[lookupId];
				if (callbackFunc) {
					callbackFunc(callbackResponse.value.response);
				}
			}
		}

	}

	this.logExit(methodName);
	return response;
	//MessageFactory.createErrorMessage = function(messagePrefix, inserts, backgroundRequest);

},

Leave a Reply