I am having big issue with this code and I already did my best and searched for many solutions, i think the issue is regarding the execution timing or something.
anyway this is the error I am facing : Uncaught Error: The collection has not been initialized. It has not been requested or the request has not been executed. It may need to be explicitly requested.
and this is the code
function GetMyTasksListList(itemId) {
var clientContextMyTasksListList = new SP.ClientContext.get_current();
var MyTasksListList = clientContextMyTasksListList.get_web().get_lists().getByTitle('All Tasks');
//Start
var MyTasksListcamlQuery = new SP.CamlQuery();
MyTasksListcamlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name="Subject_x003a_ID"></FieldRef><Value Type="Text">' + itemId + '</Value></Eq></Where><OrderBy><FieldRef Name=\'ID\' Ascending=\'FALSE\' /></OrderBy></Query></View>');
//END
this.MyTasksListcollListItem = MyTasksListList.getItems(MyTasksListcamlQuery);
//clientContextMyTasksListList.load(MyTasksListcollListItem);
clientContextMyTasksListList.load(MyTasksListcollListItem, 'Include(Title,ID,Created,Author)');
clientContextMyTasksListList.executeQueryAsync(
Function.createDelegate(this, this.onMyTasksListQuerySucceeded),
Function.createDelegate(this, this.onMyTasksListQueryFailed)
);
}
function onMyTasksListQuerySucceeded(sender, args) {
var MyTasksListlistItemEnum = MyTasksListcollListItem.getEnumerator();
var count = MyTasksListcollListItem.get_count();
var TaskatIDS = [];
var MyTasksListList = '';
if (count > 0) {
while (MyTasksListlistItemEnum.moveNext()) {
var MyTasksListListItem = MyTasksListlistItemEnum.get_current();
var MyTasksListTitle = MyTasksListListItem.get_item("Title");
//var MyTasksNots = MyTasksListListItem.get_item("Notes");
var MyTasksListCreatedDate = new Date(MyTasksListListItem.get_item("Created"));
//var userName = MyTasksListListItem.get_item("AssignedTo");//replace AssignedTo with your person column
//var user = web.ensureUser(userName);
//var email = user.get_email();
//var loginName = user.get_loginName();
var TaskId = MyTasksListListItem.get_item('ID');
TaskatIDS.push(TaskId);
var Author = MyTasksListListItem.get_item("Author");
MyTasksListList += '<tr>' +
//'<td>' + TaskId + '</td>' +
'<td rowspan="2"><a href="https://Hajjaj.sharepoint.com/sites/TMS/Lists/All%20Tasks/EditForm.aspx?ID=' + TaskId + '&Source=https://Hajjaj.sharepoint.com/sites/TMS/Pages/Dashboard.aspx" target="_self" class="btn btn-group btn-sm tipb" data-original-title="Edit Task" style="border:1px solid #dddddd; padding:5px 7px 2px 7px; margin:5px" > <span class="fa fa-pencil" style="font-size:15px"></span> </a></td>' +
'<td>' + MyTasksListTitle + '</td>' +
'<td>' + MyTasksListCreatedDate.toDateString() + '</td>' +
'<td><a href="#" class="text-info">' + Author.get_lookupValue() + '</a></td>' +
'<td><a href="https://Hajjaj.sharepoint.com/sites/TMS/Documents/Forms/Tasks_Documents_List.aspx?taskID=' + TaskId + '" target="_blank" class="btn btn-group btn-sm tipb" data-original-title="View Documents" style="border:1px solid #dddddd; padding:5px 7px 2px 7px; margin:5px" > <span class="fa fa-file-text" style="font-size:15px"></span> </a>' +
'<a href="javascript:GetCEONotesList('+TaskId+');" target="_blank" class="btn btn-group btn-sm tipb" data-original-title="View Documents" style="border:1px solid #dddddd; padding:5px 7px 2px 7px; margin:5px" > <span class="fa fa-eye" style="font-size:15px"></span> </a></td > ' +
'</tr>' +
'<tr><td colspan="4"> <table cellpadding="0" cellspacing="0" style="width:100%; border:2px solid #eee" class="table" id="CEONotes' + TaskId + '"></table> </td></tr >';
}
}
else {
MyTasksListList += '<tr><td colspan="6">No Tasks Related to this subject yet</td></tr>';
}
$('#MyTasksListContainer').html(MyTasksListList);
var TaskatIDSarrayLength = TaskatIDS.length;
for (var i = 0; i < TaskatIDSarrayLength; i++) {
alert(TaskatIDS[i]);
GetCEONotesList(TaskId);
}
//MyTasksListList += '';
//$('#MyTasksListContainer').html(MyTasksListList);
//notify_i('Info', 'What\'s Next Updated');
}
function onMyTasksListQueryFailed(sender, args) {
notify_e('Request failed', args.get_message() + '\n' + args.get_stackTrace());
}
//-----------------------------------------------------------
// CEONotes List Retrival
//-----------------------------------------------------------
function GetCEONotesList(TaskId) {
var clientContextCEONotesList = new SP.ClientContext.get_current();
var CEONotesList = clientContextCEONotesList.get_web().get_lists().getByTitle('CEONotes');
//Start
var CEONotescamlQuery = new SP.CamlQuery();
CEONotescamlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name="Task_x003a_ID"></FieldRef><Value Type="Text">' + TaskId + '</Value></Eq></Where><OrderBy><FieldRef Name=\'ID\' Ascending=\'FALSE\' /></OrderBy></Query></View>');
//END
this.CEONotescollListItem = CEONotesList.getItems(CEONotescamlQuery);
clientContextCEONotesList.load(CEONotescollListItem, 'Include(Title, Id,Task_x003a_ID,Created)');
clientContextCEONotesList.executeQueryAsync(
Function.createDelegate(this, this.onCEONotesQuerySucceeded),
Function.createDelegate(this, this.onCEONotesQueryFailed)
);
}
function onCEONotesQuerySucceeded(sender, args) {
var CEONoteslistItemEnum = CEONotescollListItem.getEnumerator();
var count = CEONotescollListItem.get_count();
//alert(count);
var target = "";
var CEONotesList = '<tr><th colspan="3">CEO Note</th><th>Date</th></tr>';
if (count > 0) {
while (CEONoteslistItemEnum.moveNext()) {
var CEONotesListItem = CEONoteslistItemEnum.get_current();
var CEONotesTitle = CEONotesListItem.get_item("Title");
var CEONotesCreatedDate = new Date(CEONotesListItem.get_item("Created"));
target = CEONotesListItem.get_item("Task_x003a_ID").get_lookupValue();
target = "#CEONotes" + target;
//alert(target);
CEONotesList += '<tr><td colspan="3">' + CEONotesTitle + '</td>' +
'<td>' + CEONotesCreatedDate.toDateString() + '</td></tr>';
}
}
else {
CEONotesList += '<tr><td colspan="6">No comment Related to this subject yet</td></tr>';
}
CEONotesList += '';
//salert("last:" + target +"Code"+ CEONotesList);
$(target).html(CEONotesList);
//notify_i('Info', 'What\'s Next Updated');
}
function onCEONotesQueryFailed(sender, args) {
notify_e('Request failed', args.get_message() + '\n' + args.get_stackTrace());
}