I am having an issue while saving an item(editform.aspx) using below PreSaveAction function. I am using JSOM to fetch some information from SharePoint 2010 list and I expect it to return true or false on success or fail function. Since Async function runs ahead of time before any value is returned it doesnt save the item. Any solution on handling it?
function PreSaveAction() {
var context = new SP.ClientContext.get_current();
var web = context.get_web();
var targetList = web.get_lists().getByTitle('Reviews');
var query = new SP.CamlQuery();
var caml = My caml query;
query.set_viewXml(caml);
var listItems = targetList.getItems(query);
results = context.loadQuery(listItems);
var callback = context.executeQueryAsync(_onSucceed, _onFail);
alert(callback); //returns undefined
return callback;
}
function _onSucceed() {
alert("Success");
return true;
}
function _onFail() {
alert('failed reading data');
return false;
}