Click here to Skip to main content
14,658,931 members
Rate this:
Please Sign up or sign in to vote.
I am trying to add to a Calender List but dont get it to work, i dont get any value either,

Can someone help me?

function createItem() {

   var targetList = list.getByTitle('AppbokningarList');
    var listItemTitle = document.getElementById('Textrubrik').value;
    alert(listItemTitle);
    var listItemCustom = document.getElementById('datepicker').value;
    alert(listItemCustom);
    var listItemFromTime = document.getElementById('timepicker').value;
    alert(listItemFromTime);
    var listItemtoDate = document.getElementById('datepickerto').value;
    alert(listItemtoDate);
    var listItemToTime = document.getElementById('timepickerTo').value;
    alert(listItemToTime);
    var listItemBeskrivning = document.getElementById('Textbeskrivning').value;
    alert(listItemBeskrivning);
    var result = listItemCustom + "T" + listItemFromTime +":00" + "Z";
    var result2 = listItemtoDate + "T" + listItemToTime + ":00" + "Z";


    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><Query><Where><And><Eq><FieldRef Name=\'EventDate\' /><Value IncludeTimeValue=\'TRUE\' Type=\'DateTime\'>' + result + '</Value></Eq><Eq><FieldRef Name=\'EndDate\' /><Value IncludeTimeValue=\'TRUE\' Type=\'DateTime\'>' + result2 + 'Z</Value></Eq></And></Where></Query></View>');
    this.collListItem = targetList.getItems(camlQuery);
    context.load(collListItem);


    context.executeQueryAsync(
        function() {
            var itemCount = collListItem.get_count();
            if (itemCount > 0) {

                alert(itemCount);   

            } else {
                alert('go ahead and create the event the user wants');

                var listItemCreateInfo = new SP.ListItemCreationInformation();
                var newItem = targetList.addItem(listItemCreateInfo);
                newItem.set_item('Title', listItemTitle);
                newItem.set_item('EventDate', result);
                newItem.set_item('EndDate', result2);
                newItem.set_item('Description', listItemBeskrivning);

                newItem.update();
                context.load(newItem);
                context.executeQueryAsync(

        function () {
            alert("update");
                },
                function(sender, args) {
                    alert(args.get_message());


                }
    );

            }
        },
        function(sender, args) {
            alert(args.get_message());


        }
    );


}
Posted
Comments
Pradip R 4-Dec-14 5:41am
   
By looking at your code, Client context is not being loaded. Have you loaded it first?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100