I have got a submit button which gets the information from a form in my lightbox, e.g. first name, last name, Rating number, Review Title, Review Comments and updates the product Reviews dataset/collection. I also want the button to do some calculations and update 3 of the linked items fields in the giftIdeas dataset, e.g. Total review number, Total count of reviews for that product and the average rating.
My current code will do everything i need it to, but it updates the top field in the giftIdea’s dataset rather than the current item in the giftIdea’s dataset.
Lightox code
import  wixWindow  from  ‘wix-window’;
import  wixData  from  ‘wix-data’;
$w.onReady(() => {
let  ProductRecord = wixWindow.lightbox.getContext();
if  (ProductRecord) {
// Extract name and image from record
let  name = ProductRecord[‘productName’];
let  image = ProductRecord[‘productImage’];
// Add these values to your UI elements…
$w(‘#ProductName’).text = name;
$w(‘#ProductImage’).src = image;
}
})
export function  SubmitReview_click(event) {
let  ProductRecord = wixWindow.lightbox.getContext();
if  (ProductRecord) {
let productID = ProductRecord[‘_id’];
    $w('#productReviews').onReady(() => { 
        $w('#productReviews').setFieldValue("productId", productID); 
    }) 
} 
let currentItem = ProductRecord;
let currentItemRating = currentItem.rating;
let  ratinginput = $w(‘#RatingsInput’).value;
let  newRatingValue = (currentItemRating + ratinginput);
let  currentNoRatings = currentItem.noRatings;
let  newTotalRatings = (currentNoRatings + 1);
let  newAvRating = (newRatingValue / newTotalRatings);
$w(‘#GiftIdeas’).setFieldValue(‘rating’, newRatingValue)
$w(‘#GiftIdeas’).setFieldValue(‘noRatings’, newTotalRatings)
$w(‘#GiftIdeas’).setFieldValue(‘avRating’, newAvRating)
}
Please help!!