on.submit code doesn't update SharePoint list
Posted: 03 May 2016
Scenarios:
var formOpenedTime = new Date();
//Compare Current User to Assigned To
SP.SOD.executeOrDelayUntilScriptLoaded((function() {
var ctx = new SP.ClientContext.get_current();
var web = ctx.get_web();
ctx.load(web);
user = web.get_currentUser();
user.retrieve();
ctx.executeQueryAsync(
function() {
currentuser = user.get_loginName();
assignedTo = fd.field('AssignedTo').value().dictionaryEntries[0].AccountName;
if ( currentuser == assignedTo ) {
//CALCULATE TIME WORKED ON ITEM
//Get Time Stamp of when form was Closed
var formClosedTime = new Date();
//Calculate total time form opened
var timeElapsed = (formClosedTime - formOpenedTime);
var seconds = timeElapsed / 1000
fd.field('calcWorkingTime').value(seconds);
//Update Time
var currentTime = parseFloat(fd.field('calcWorkingTime').value());
var oldTime = parseFloat(fd.field('TotalTime').value());
var newTime = currentTime + oldTime;
fd.field('TotalTime').value(newTime);
fd.field('EndTime').value(newTime);
}
});
}), "SP.js");
I've commented everything out and verified that the on.submit wrapper is solely responsbile for the changed value not hitting the list.
I cannot figure out why
- Fire the following code when the form opens --> The code works and the SharePoint list is updatedwith the new value.
- Fire the following code in a fd.onsubmit(function() { }) wrapper. The code works but the SharePoint list is not updated with the new value.
var formOpenedTime = new Date();
//Compare Current User to Assigned To
SP.SOD.executeOrDelayUntilScriptLoaded((function() {
var ctx = new SP.ClientContext.get_current();
var web = ctx.get_web();
ctx.load(web);
user = web.get_currentUser();
user.retrieve();
ctx.executeQueryAsync(
function() {
currentuser = user.get_loginName();
assignedTo = fd.field('AssignedTo').value().dictionaryEntries[0].AccountName;
if ( currentuser == assignedTo ) {
//CALCULATE TIME WORKED ON ITEM
//Get Time Stamp of when form was Closed
var formClosedTime = new Date();
//Calculate total time form opened
var timeElapsed = (formClosedTime - formOpenedTime);
var seconds = timeElapsed / 1000
fd.field('calcWorkingTime').value(seconds);
//Update Time
var currentTime = parseFloat(fd.field('calcWorkingTime').value());
var oldTime = parseFloat(fd.field('TotalTime').value());
var newTime = currentTime + oldTime;
fd.field('TotalTime').value(newTime);
fd.field('EndTime').value(newTime);
}
});
}), "SP.js");
I've commented everything out and verified that the on.submit wrapper is solely responsbile for the changed value not hitting the list.
I cannot figure out why