Getting the member name and send it to a dataset

Hi there,

I got a custom form that triggers and email. It works fine except now that I added the Member name.
I got the member name and it is displayed correctly but I can not make this member name be included in the dataset. All fields get to the data set after submitting except ‘lawyerName’. That field remains empty in the dataset.
The field and its value are connected to the dataset, also the email works fine. Some help please.

This is my code:

import wixUsers from ‘wix-users’ ;
import wixData from ‘wix-data’ ;

$w.onReady( function () {

wixData.query( “Members/PrivateMembersData” )
.eq( “_id” , wixUsers.currentUser.id)
.find()
.then((results) => {

          $w( "#lawyerName" ).value = results.items[ 0 ].name; // This works fine displaying the name! 

//console.log(results.items[0].name);
})

$w( “#dataset1” ).onAfterSave( () => {

if (wixUsers.currentUser.loggedIn) {
//console.log(wixUsers.currentUser);
const userId = wixUsers.currentUser.id;
wixUsers.emailUser( ‘RyEca9M’ , userId, {
variables: {

“attorneyName” : $w( “#lawyerName” ).value, // ONLY THIS FIELD IS NOT SAVED IN THE DATASET!!!
“clientName” : $w( “#firstName” ).value,
“clientLastName” : $w( “#lastName” ).value,
“clientPhone” : $w( “#clientPhone” ).value,
“clientEmail” : $w( “#clientEmail” ).value,
//“clientAddress”: $w(“#addressInput”).value,
“typeOfAccident” : $w( “#typeAccident” ).value,
“additionalInfo” : $w( “#AditionalInfo” ).value
}
} )
.then( () => {
console.log( “Triggered email sent” );
} )
. catch ( (err) => {
console.log( “Triggered email NOT SEND!” );
} );
}
} );

} );

Hello.

You need to use a temporary variable to store the value of your variable instead if trying to pass it to an input element and then retriving it.

let name;//This declaration should be on top of your code panel

name = results.items[0].name;

"attorneyName": name, 

Good luck!