I have some code to automatically populate the user name of the current user in a Data Table field called "Verified By". See attached code. What has started happening is when a new record is added on top of an existing record, the previous "Verified By" username is replaced with the person adding the new record.
Please see video for an example and focus on the "Verified By" column. Why is this happening?
@IliaLazarevskii the issue described above (with video) is happening again. The "Verified By" username column value is replaced with the next person's name that's adding the new record to the data table. The names that populate the Verified By column need to be "locked" and intact, and shouldn't change. Help!
Please use this code to populate only new lines with user name:
var dt = fd.control('DataTable1');
var username = _spPageContextInfo.userDisplayName;
dt.widget.bind('beforeEdit', function(e) {
var model = e.model;
if (model.isNew()) {
model.set('Column1', username);
}
});
Also, I suggest updating your code so there is only one spRendered() function and all teh code is inside it. No need to warp each action in it.
How do I also use the code above to incorporate auto populating today's date into the date column as new records are added? That functionality used to be native but it's not anymore.
Also getting "Unmatched '{'" error with your code:
The editor shows that the code is incorrect. Most likely, a closing curly brace is missing. Read the error's tooltip to find the error.
And for the date field the code is similar:
var dt = fd.control('DataTable1');
var username = _spPageContextInfo.userDisplayName;
dt.widget.bind('beforeEdit', function(e) {
var model = e.model;
if (model.isNew()) {
model.set('Column1', username);
//set date column
model.set('DateColumn', new Date());
}
});
@Margo I got it to work but now the issue is that when the new record is created in the table, the dropdown in the 'Assessment' column cannot be accessed unless I refresh the browser. Is this a bug?
var dt = fd.control('DataTable1');
var username = _spPageContextInfo.userDisplayName;
dt.widget.bind('beforeEdit', function(e) {
var model = e.model;
if (model.isNew()) {
model.set('Column1', username);
//set date column
model.set('DateColumn', new Date());
}
// HERE DO THE REFRESH
dt.refresh()
});
@ParAvion can you share your entire script and what you have in the designer? Assessment is a dropdown field with predefined values in the "Options" or do you load the data from other source?
var dt = fd.control('DataTable1');
var username = _spPageContextInfo.userDisplayName;
var date = new Date().toISOString();
dt.widget.bind('beforeEdit', function(e) {
var model = e.model;
if (model.isNew()) {
model.set('Approver', username);
//set date column
model.set('Date', date);
}
});