Skip to content

Instantly share code, notes, and snippets.

@mutuadavid93
Created June 19, 2017 11:51
Show Gist options
  • Save mutuadavid93/561e91e84927c1f26767631434d7f13d to your computer and use it in GitHub Desktop.
Save mutuadavid93/561e91e84927c1f26767631434d7f13d to your computer and use it in GitHub Desktop.
// Add data into a list using CSOM
function apbObjectivesSection() {
alert("We are in the first function");
var currentCrx = SP.ClientContext.get_current();
var web = currentCrx.get_web();
try {
var list = web.get_lists().getByTitle("MyObjectives");
var itemInfoObj = new SP.ListItemCreationInformation();
// Collect UserName
var appraiseUserName = $('#appraiseeUserName').val();
var managerUserName = $('#immediateManager').val();
var realRef = "REF_" + $('#appraiseeUserName').val().replace(/\\/g, '') + $('#immediateManager').val().replace(/\\/g, '');
// Loop through the trs
$('#section_one tr').each(function (index, item) {
var apbObj = $($(this).find('.performObj')).val();
var weight = $($(this).find('.weighting')).val();
var evidence = $($(this).find('.Evidence')).val();
var hinders = $($(this).find('.hinders')).val();
var selRating = $($(this).find('.selRating')).val();
var mgerRate = $($(this).find('.mgersRate')).val();
var agreedRate = $($(this).find('.agreedRate')).val();
var newAddedItem = list.addItem(itemInfoObj);
console.warn("Tr number: " + index + " " + apbObj + " " + weight + " " + agreedRate);
newAddedItem.set_item("Title", realRef);
newAddedItem.set_item("Weighting", weight);
newAddedItem.set_item("AchievementEvidence", evidence);
newAddedItem.set_item("HinderingFactors", hinders);
newAddedItem.set_item("SelfRating", selRating);
newAddedItem.set_item("ManagerRating", mgerRate);
newAddedItem.set_item("APBObjective", apbObj);
newAddedItem.set_item("AgreedRating", agreedRate);
newAddedItem.update();
currentCrx.executeQueryAsync(onQuerySuccess, onQueryFailure);
}); //End Each Loop
}catch(Ex){
alert("apbObjectivesSection() threw an error: " + Ex.message);
}
} //apbObjectivesSection
function onQuerySuccess() {
alert('Data inserted Successfully');
}
function onQueryFailure(sender, args) {
alert('Request Failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}
$('#saveSectOne').click(function (event) {
event.preventDefault();
apbObjectivesSection(); // invoke the func
});
// ## End APB Section 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment