Hi there,
So, I have an ‘afterQuery’ hook on my dataset that prompts it to extract content from the _owner field anytime the dataset is queried.
I also have a dynamic item page to show the contents of that dataset. On that page, I placed a ‘Like’ button that increases the count of the dataset’s ‘like’ field with code, then saves the dataset so the updated ‘Like’ count is now available.
The problem is, it appears that this code clashes with the hook, because I get a callback error that says : An error occurred in one of datasetReady callbacks DatasetError: Operation (onCurrentIndexChanged) not allowed during save
Is there anyway I can avoid this conflict by reconfiguring some of my code?
This is the hook I have on the backend:
export function Characters_afterQuery(item, context) {
//TODO: write your code here...
item.authorID = item._owner;
return item;
}
And this is the code I have on the frontend:
//Voting and Viewing code
export function ifNull(a) {
return (a === undefined) ? 0 : a;
}
var currentItem, ds;
export function dynamicDataset_ready(event) {
ds = $w('#dynamicDataset');
currentItem = ds.getCurrentItem();
if (currentItem.characterReport >= 10) {
$w('#ReportGrey').hide();
$w('#ReportTextPurple').show();
}
//Increment the number of views on this item
let views = ifNull(currentItem.charViews) + 1;
//In case the number of votes is null, set it to zero
let votes = ifNull(currentItem.charLikes);
//In case the number of votes is null, set it to zero
let report = ifNull(currentItem.characterReport);
ds.setFieldValue('charViews', views);
ds.setFieldValue('charLikes', votes);
ds.setFieldValue('characterReport', report);
ds.save();
}
export function LikeHeartGrey_click(event) {
//Add your code for this event here:
$w('#LikeHeartGrey').hide();
//increment the number of votes and save it
ds.setFieldValue('charLikes', +1);
ds.save();
}
export function ReportGrey_click(event) {
//Add your code for this event here:
$w('#ReportGrey').hide();
$w('#ReportTextPurple').show();
//increment the number of votes and save it
ds.setFieldValue('characterReport', +1);
ds.save();
}
Any ideas would be very welcome.