Vanaraj n

Vanaraj n

  • NA
  • 18
  • 14.4k

executeQueryAsync function call not working using for loop

May 4 2016 12:39 AM
I am having values in result[15452,33616] when using for loop ,The for loop for i=0 it takes the value of result[0]=15452 ,it is not going to async function.The loop continuing ,after loop over only its going to async function.While going to async function it taking only last array value (e.g-33616) of for loop and fetching the data for that pushing to another array and final push into grid.for array[0] (e.g -15452)values data is not fetching . & it is repeating the same row three times for 33616.Please reply as soon as earlier.
for (var i = 0; i < result.length; i++) { var isFirst = 1; var context = new SP.ClientContext.get_current(); var lists = context.get_web().get_lists(); var associatedProjectsList = lists.getByTitle('Master Project Data'); var camlQueryAssociatedProjects = new SP.CamlQuery();             camlQueryAssociatedProjects.set_viewXml('<View><Query><Where><Eq><FieldRef Name="ID"/><Value Type="Number">' + result[i]["ESI_ProjectSeqNoLookupId"] + '</Value></Eq></Where></Query></View>');             associatedProjectsItems = associatedProjectsList.getItems(camlQueryAssociatedProjects);             context.load(associatedProjectsItems);             context.executeQueryAsync(function () {                 MPDS = MasterProjectDataSuccess(); if (isFirst == 1) {                     rfaarr = MPDS;                     isFirst = 0; } else {                      rfaarr = $.extend(rfaarr, MPDS);                     inputoJGrid.push(rfaarr); self.PushToGrid(inputoJGrid); } }, MasterProjectDataFailure); var lists1 = context.get_web().get_lists(); var associatedProjectsList1 = lists1.getByTitle('Project Users'); var camlQueryAssociatedProjects1 = new SP.CamlQuery();             camlQueryAssociatedProjects1.set_viewXml('<View><Query><Where><Eq><FieldRef Name="ID"/><Value Type="Number">' + result[i]["ESI_ProjectSeqNoLookupId"] + '</Value></Eq></Where></Query></View>');             associatedProjectsItems1 = associatedProjectsList1.getItems(camlQueryAssociatedProjects1);             context.load(associatedProjectsItems1);             context.executeQueryAsync(function () {                 PUS = ProjectUsersSuccess(); if (isFirst == 1) {                     rfaarr = PUS;                     isFirst = 0; } else {                     rfaarr = $.extend(rfaarr, PUS);                     inputoJGrid.push(rfaarr); self.PushToGrid(inputoJGrid); } }, ProjectUsersFailure); } }); }; function MasterProjectDataSuccess() { var listItemEnumerator = associatedProjectsItems.getEnumerator(); while (listItemEnumerator.moveNext()) { var cur = listItemEnumerator.get_current();         rfalistfetch["ProjectTitle"] = cur.get_item("ESI_ProjectName");         rfalistfetch["SequenceNo"] = cur.get_item("ESI_ProjectSequenceNo");         rfalistfetch["Division"] = cur.get_item("ESI_Division").get_lookupValue();         rfalistfetch["SubDivision"] = cur.get_item("ESI_SubDivision").get_lookupValue();         rfalistfetch["Status"] = cur.get_item("ESI_Status").get_lookupValue();         rfalistfetch["ProjectType"] = cur.get_item("ESI_ProjectCategory").get_lookupValue(); var Budget = cur.get_item("ESI_BudgetYear"); var dutyDateObj = new Date(Budget); var day = "" + dutyDateObj.getDate(); if (day.length == 1) {         day = "0" + day; } var month = "" + (dutyDateObj.getMonth() + 1); if (month.length == 1) {         month = "0" + month; } var year = "" + (dutyDateObj.getYear() + 1); if (year.length == 1) {         year = "0" + year; }         rfalistfetch["BudgetYear"] = dutyDateObj.getFullYear();         rfalistfetch["BMP"] = cur.get_item("ESI_BeginningMP");         rfalistfetch["EMP"] = cur.get_item("ESI_EndingMP");         rfalistfetch["State"] = cur.get_item("ESI_State").get_lookupValue();         rfalistfetch["Station"] = cur.get_item("ESI_Station");         rfalistfetch["SubCategory"] = cur.get_item("ESI_SubCategory").get_lookupValue();         rfalistfetch["LineSegment"] = cur.get_item("ESI_LineSegment");         rfalistfetch["DOT"] = cur.get_item("ESI_DOTNumber");         rfalistfetch["BriefScope"] = cur.get_item("ESI_BriefScope");         rfalistfetch["CPAR"] = cur.get_item("ESI_CPAR");         rfalistfetch["ProjectID"] = cur.get_item("ID").toString(); return rfalistfetch; } };  function ProjectUsersSuccess() { var listItemEnumerator1 = associatedProjectsItems1.getEnumerator(); while (listItemEnumerator1.moveNext()) { var curr = listItemEnumerator1.get_current();         rfalistfetch["ESDirector"] = curr.get_item("ESI_Director").get_lookupValue(); return rfalistfetch; } };
 

Answers (2)