Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
225 views
in Technique[技术] by (71.8m points)

javascript - Loop and insert to Sharepoint List using executeQueryAsync

I'm trying to loop into a list based on the duration selected. So if the user for example selects 6 months then it's 2 Quarters or it's 3 Quarter if they select 9 months. (Q1 & Q2 & Q3).

The issue I'm facing is my that my for loop is only inserting the last item in the for loop and ignoring and ignoring the first ones in the queue.

I can't figure out why only the last Quarter is being inserted

function RetrieveListItems(){   
    var clientContext = new SP.ClientContext.get_current();
    var oList = clientContext.get_web().get_lists().getByTitle('StreamObjectives'); 
    var camlQuery = new SP.CamlQuery();
    var Quarter = "Q";
    var i;
    var quarterPeriod;
    if($("select[id^='RotationDuration'] option:selected").text()=='3 months'){
        quarterPeriod= 2;
    
    }
    else if($("select[id^='RotationDuration'] option:selected").text()=='6 months'){
        quarterPeriod= 3;
    
    }
    else if($("select[id^='RotationDuration'] option:selected").text()=='9 months'){
        quarterPeriod= 4;
        
    }
    else if($("select[id^='RotationDuration'] option:selected").text()=='12 months'){
        quarterPeriod= 5;
    
    }
    for (i = 1; i < quarterPeriod; i++) {
    var QuarterChosen = Quarter.concat(i);
    camlQuery.set_viewXml("<View><Query><Where><And><Eq><FieldRef Name='StreamPosition' /><Value Type='Lookup'>"+ObjectiveRole+"</Value></Eq><Eq><FieldRef Name='Quarter' /><Value Type='Choice'>"+QuarterChosen+"</Value></Eq></And></Where></Query> </View>");
    this.collListItem = oList.getItems(camlQuery);
    clientContext.load(collListItem);
    console.log(collListItem);
    clientContext.executeQueryAsync(function(){         
            var ProjectAssignment = '';
            var DevelopmentMethod = '';
            var Quarter = '';
            var StreamPosition = new SP.FieldLookupValue();
            var TitleOfObjective = '';
            var Weighting = '';
            var stringpost = '';
            var listItemEnumerator = collListItem.getEnumerator();              
            while (listItemEnumerator.moveNext()) {
                var oListItem = listItemEnumerator.get_current();
            
                DevelopmentMethod = oListItem.get_item('DevelopmentMethod');
                ProjectAssignment = oListItem.get_item('ProjectAssignment');
                Quarter = oListItem.get_item('Quarter');
                StreamPosition = oListItem.get_item('StreamPosition').get_lookupValue();
                stringpost = StreamPosition;
                console.log(stringpost);
                TitleOfObjective = oListItem.get_item('Title');
                Weighting =  oListItem.get_item('Weighting');
                AddTraineeItemsToList(clientContext,DevelopmentMethod,stringpost,ProjectAssignment,StreamPosition,TraineeID,TitleOfObjective,Weighting,Quarter)
            }

            
    }, function(sender, args){
        console.log('Request failed. ' + args.get_message() + '
' + args.get_stackTrace());
    });  
    
    }
                //form.SubmitClientForm();
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share

2.1m questions

2.1m answers

62 comments

56.7k users

...