Unable to get Fname Lname concatenation to work!

I am trying to get two fields concatenated so that they come out properly. For example:

John Doe NOT like the way they are now John Doe, as the text boxes are set to contain the longest possible firstname without doing a hard return.

I found the following code block in other posts

$w.onReady( function () {
let search = ‘1’;
let saved_dash = $w(‘#regDash’);
session.setItem(“#dash#”, saved_dash);

const currentItem = $w(‘#dynamicDataset’).getCurrentItem();
let Fullname = ${currentItem.fname} ${currentItem.lname};
$w(‘#fullName’).text = Fullname;
console.log(Fullname);
});

But running in preview mode with console log I get:
undefined undefined

Hi,

The dataset is not yet ready when you try reading the current item.
Try this:

$w.onReady(function () {
 let search = '1';
 let saved_dash = $w('#regDash');
  session.setItem("#dash#", saved_dash);

  $w('#dynamicDataset').onReady(() => {
 const currentItem = $w('#dataset1').getCurrentItem();
 let Fullname = `${currentItem.fname} ${currentItem.lname}`;
    $w('#fullName').text = Fullname;
    console.log(Fullname);
  })
});

Got a runtime error in Preview mode… In my page, the fname and lname is included in #dataset3.

Hi, please check that dataset3 has some data and isn’t empty. And try $w(’ # dataset3 ‘).onReady(() => { const currentItem = $w(’ # dataset3 ').getCurrentItem();

Thanks. Well, that worked, but this is in a repeater, so the information on the first record was repeated on ever other item in the repeater. Maybe I need to move this somewhere in the repeater code block.

Actually, there is no Repeater Code Block per se… I think thats why it needed to be #dynamicDataset???

Should be the same dataset used in both cases - then $w(’ # dynamicDataset ‘).onReady(() => { const currentItem = $w(’ # dynamicDataset ').getCurrentItem(); . It means you can get current item for a dataset only after this dataset is ready.

Sorry, you are not understanding the problem. The repeater items are in the dynamic dataset, the user name etc… is in a second dataset and is linked to the repeater thru a common email address.

Could you please provide a site URL to understand what is wrong?

This has been resolved by a wix consultant.