I have a case where I enter a value in a specific cell and the rest of them are auto-populated. On beforeSave event I can see that the object value has all the inserted values but when I check the list the 2 auto-populated fields are not saved. If I try to enter the values manually then it works as expected.
Here is the code that triggers the auto-population:
fd.control('KitsDT').$on('change', function (value) {
if (value) {
for (var i = 0; i < value.length; i++) {
if (_currentEditField === 'KitLotNumber') {
//kit lot number
let kitLotnumbers = kitsandreagents.filter(function (k) { return k.UpdatedValue === value[i].KitLotNumber });
if (kitLotnumbers.length > 0) {
value[i].KitBarcode = kitLotnumbers[0].Title;
value[i].KitExpiry = new Date(kitLotnumbers[0].SubmittedDate);
}
else {
value[i].KitExpiry = null;
}
}
else {
//kit bar code
let kitBarcodes = kitsandreagents.filter(function (k) { return k.Title === value[i].KitBarcode });
if (kitBarcodes.length > 0) {
value[i].KitLotNumber = kitBarcodes[0].UpdatedValue;
value[i].KitExpiry = kitBarcodes[0].SubmittedDate;
}
else {
value[i].KitExpiry = null;
}
}
}
}
fd.control('KitsDT').widget.refresh();
fd.control('KitsDT').saveState(value);
});
Dear @george,
Small issue with the code - thank you for pointing it out! Just add this line dt.$emit('change'); for the change to be recorded in SharePoint field:
Hi @Nikita_Kurguzov ,
Thank you for your piece of code, I had the same problem as mate @george ,
I did something similar without .saveState because I have this piece of code:
Dear @Stepan,
Try removing different parts, see where the error comes from. saveState() is important to fix changes after they're applied, so you might also need it.
I think the variable "val" is not correct in this change, but cannot figure it out.
I only use one line (row) in data Table - every changes happen in that one row (first row).
The post above is a screenshot from the browser.
Whenever I do a change and $emit("change") and saveState triggers, the error appears in the console.
Although, I totally refactored the code and fields, so I have left the DataTable out and created several SharePoint one line text fields and do calculations among them.
So there is no problem at this moment, but thank you for your help