slice a fieldkey for non-logged in user

Hi all have the following code, can i use this somehow? to slice the first four characters of ${firstName} in text102

and then only show text102 to non-logged in users

$w.onReady(() => {
$w( “#dynamicDataset” ).onReady(() => {
const item = $w( “#dynamicDataset” ).getCurrentItem();
const firstName = item.firstName;

        $w( '#text102' ).text = `Say hello to ${firstName}`; 
     
    }) 
}) 

})

let user = wixUsers.currentUser;
let isLoggedIn = user.loggedIn;
$w.onReady(() => {
if (isLoggedIn) {
doIfLoggedIn();
} else {
$w( “#columnStrip13” ).expand();
$w( “#columnStrip12” ).collapse();

} 
wixUsers.onLogin(u => { 
    isLoggedIn = u.loggedIn; 
    doIfLoggedIn(); 
}) 

function doIfLoggedIn() {
$w( “#columnStrip12” ).expand();
$w( “#columnStrip13” ).collapse();
}

It’s not easy to understand from your code what exactly you’re trying to do.
Can you add more details?

Hi J.D. hope you are keeping well.

yes so my code already exists for other functions, in fact i think you helped me with some it it previously but this request for help is an addition and i thought the complete code that i’ve included might be useful

I have a field key that shows exactly what it should for the logged in owner of the key, what i would like to do is use the same field key but slice away the first 4 characters and include another field key as the text string for non-logged in users so that the text string reads properly for them

does this make sense at all?
Regards
Adam

@adcatch02 not really. I’d guess that the firstName key would be undefined for non-member visitors. So how do you want to slice an undefined value?

The fieldkey already exists (has already been created and stored in the collection, so is defined it just needs to be sliced.

So do something like:

if(!isLoggedIn){
firstName = item.firstName.slice(4);
}

(Make sure to put i tin the right place)

@jonatandor35 thanks and will that work with this
$w( ’ #text102 ’ ).text = Say hello to ${firstName};

I am like J.D. here and slightly confused as well.

If the user is logged in then you can get their firstname either by use of code and display it in a text box like you have done, or you simply link a textbox to your members dataset and it will simply show the name from the firstname field of that logged in user.

However, as J.D. has already said above, if the user is not logged in, then you will not have any firstname data to use from the dataset and the value will be undefined and return nothing.

Are you creating another form that non logged in users are using before they get to this stage of showing their first name? Like if somebody contacts you through your website and they are given a contactId for example?

If it is then you would need to be explaining that to us here so that we understand your process and not make it sound like you are trying to show a logged in users firstname to a non logged in user.

Another way to do this if you don’t want them to be made as contacts on your site, is to just make use of Wix Storage API and save the firstname value and then recall it in the form that you need it on. That way you are not having to have an additional database just for this
https://www.wix.com/corvid/reference/wix-storage.html

Or do you have a set default value that you want to be put in the text box if the user is not logged in and it only changes if the user is logged in?

If this is not what you are doing, then please explain more.

Thanks guys, so the only answer i can give you is that a dynamic dataset that has been pre-populated and saved before a non-logged in user arrives at this page shows all the fields that i’ve connected

the code at the top of this page shows two different columnstrips and i have placed two different text strings in those
1, One which welcomes a logged in user personally i.e. welcome Joe to Adam’s page
the other
2. for a guest i.e. welcome guest to Adam’s page (Adam being a fieldkey name and field- already in the collection)

but both show a fieldkey of first name which is fine

so on this is about using another text string but this time slicing the field and placing the code somewhere in the not logged in code section above

ok hopefully i can simplify this, please do not worry as the dataset has already been filled previously

i have the following text element
#text1 that i would like to do the following with

$w( ’ #text1 ’ ).text = ${fieldKey} (slice2 characters and add 1 character space) ${fieldKey};

is this possible please
Thanks
Adam