What's Wrong with Code - Losing my mind

I cannot for the life of me understand why this code is not working. I have a Dynamic Page set up for each user according to their ID. If a member is viewing their respective page, I want to have certain items show/expand.

I am 99.9% sure that itemId and userId equal each other. However, this simple if function is not making the groups show up???

$w.onReady(() => {
  $w('#dynamicDataset').onReady(() => {
  	let userId = wixUsers.currentUser.id.trim();
  	let item = $w('#dynamicDataset').getCurrentItem();
        let itemId = item._id.trim();
  
	if (userId === itemId) {
		$w("#group5").show();
		$w("#group4").show();
		$w("#group5").expand();
		$w("#group4").expand();
}
});
});

Hi!

First guess is problem with ===.
Here’s the details - What is the difference between =,==, and === in JS? | Codecademy

You can check if it’s really true by adding this:


$w.onReady(() => {
  $w('#dynamicDataset').onReady(() => {
  	let userId = wixUsers.currentUser.id.trim();
  	let item = $w('#dynamicDataset').getCurrentItem();
        let itemId = item._id.trim();
  
        console.log(userId === itemId)      
  
	if (userId === itemId) {
		$w("#group5").show();
		$w("#group4").show();
		$w("#group5").expand();
		$w("#group4").expand();
}
});
});

Mikhail – Thanks for the response and nice idea, but I don’t think that is the issue. Since I am using UserID I cannot preview this issue, I have to publish and actually log in if I want to test it. I also cannot view the console.log on a published site.

To add to the mystery, I tried just hard-coding a view and previewing the code below. It works PERFECTLY in preview mode. When I publish, it doesn’t work. Could this be a bug with Wix Code? Any Wix people have thoughts?:

 if ("94bef7ea-28b4-4575-9641-2d29e0a34ba6") === itemId) { 
 $w("#group5").show(); 
 $w("#group4").show(); 
 $w("#group5").expand(); 
 $w("#group4").expand(); 
 } 

David, you CAN console.log in Publish Mode, but it has to be in the browser´s console. In most browsers, this comes up with Ctrl-Shift-I. So then you can test what Mikhail suggested.

Thanks Giri! This worked and I discovered there was a different piece of code that was causing the error. For some reason error wasn’t showing up in preview but was in live, so I now got it.