Button to add row to datatable


We are trying to make a button on a form that when clicked, adds the current user on Sharepoint to a list. The following code is what we've used for the onclick() attribute of the button.

var currentUser = _spPageContextInfo.userDisplayName;
var list = pnp.sp.web.lists.getByTitle("List%20Name");
list.items.add({Title: currentUser});
return fd.save();

However this isn't working, what are we doing wrong?


Hello @thomas,

The code is working.

Please make sure that the name of the list is correct.

Please also check the errors in the console(F12) and share its screenshot to troubleshoot the issue.