Dynamic page issue : empty url when cms complete

Question:
How to correct a “empty URL” error on dynamic pages ?

Product:
Wix studio editor

What are you trying to achieve:
I want to make it easier to create a set of fairly similar pages using a CMS collection and dynamic pages. I have about sixty project pages to create, each consisting of:
Title / Subtitle / Main 16:9 video + a variable number (from 0 to 18) of additional videos with different ratios: 16:9 / 9:16 or 4:5. The videos are embedded using iframes. Following some advice, I set up a “projects” collection that references a “videos” collection.

I get the title and subtitle fine; but my problem is that when I run tests, with the following :
$w.onReady(function () {
const item = $w(“#dynamicDataset”).getCurrentItem();

if (item && item.mainVideoUrl) {
const ratio = item.mainRatio || “16:9”;
const padding = getRatioPadding(ratio);

const html = `
  <div style="padding:${padding}% 0 0 0;position:relative;">
    <iframe 
      src="${item.mainVideoUrl}" 
      frameborder="0" 
      allow="autoplay; fullscreen; picture-in-picture; clipboard-write; encrypted-media" 
      style="position:absolute;top:0;left:0;width:100%;height:100%;" 
      title="Main Video">
    </iframe>
  </div>
`;

$w("#htmlMainVideo").postMessage(html);

}
});

function getRatioPadding(ratio) {
switch (ratio) {
case “9:16”:
return 177.78;
case “4:5”:
return 125;
case “16:9”:
default:
return 56.25;
}
}

I get error messages like:

UserError: datasetApi ‘getCurrentItem’ operation failed
Caused by DatasetError: Operation (getCurrentItem) is not allowed because the field used to build this page’s URL is empty

My URLs are structured like this: /projects/[title]/[subtitle] and my collection is complete. The site isn’t published yet — could that be the reason?
I can’t seem to fix the issue, but I don’t want to publish the site just yet because I’m still testing and nothing is final.

What have you already tried:
Check the slug creation / Collection complete and correct.

Additional information:
It’s my first wix studio project, the potential is crazy but I’m clearly a newbie. I want to succeed !! Many thanks

if any fields in the CMS are empty for the url structure the error will occur. Also maybe th ecalling getCurrent before the dataset is ready

try adding

$w.onReady(function () {
  $w("#dynamicDataset").onReady(() => {
    const item = $w("#dynamicDataset").getCurrentItem();

Thanks a lot for your reply ! There is no empty field in the CMS :confused: and I have already the on Ready function (it’s not clear in the message it appears out of the code box)…

See the second line of the code I posted

Oh sorry, yes thanks !! There is no error anymore, still bugged cause my video doesn’t show up but URL issue is gone, great ! Thanks

So maybe an issue with iframe and dynamic pages. How are they stored in the CMS and what code is on the iframe?

Sorry for the late reply.
In the CMS the field is : mainVideoUrl and looks like this :

And the code on the iframe is : htmlMainVideo

this url with right size : https://player.vimeo.com/video/822075660?autoplay=1&loop=1&muted=1&background=1&badge=0&autopause=0&player_id=0&app_id=58479