0

I have a list, a list filter and two date filters(Start date and end date) in a page. First I have to filter list using this filters and then I have to approve whatever item are left in the list after filtering.

I am using the following JavaScript code.

    <script type="text/javascript">

//var siteUrl = '/projects/SharePoint2013-Demo/TimesheetManagementSystem/';
var oList = null;
var web = null;
var clientContext  = null;



function retrieveListItems() {

var filterValue =document.getElementById("ctl00_ctl41_g_1c91c2d4_fbbb_4792_8507_ba589e5be222_SpListPicker_SelectionBox");
var StartDate=document.getElementById("ctl00_ctl41_g_ed4beb82_8f7e_4389_bb35_a44188462aab_DateFilterPicker_DateFilterPickerDate");  
var EndDate=document.getElementById("ctl00_ctl41_g_07c2185d_e903_4010_8a84_b2d9536a5549_DateFilterPicker_DateFilterPickerDate");
alert(filterValue.value );
alert(StartDate.value);
alert(EndDate.value);


    clientContext = new SP.ClientContext.get_current();
    oList = clientContext.get_web().get_lists().getByTitle('TimeSheetList');
    clientContext.load(oList);

    clientContext.executeQueryAsync(LoadList, onQueryFailed);        


}


function LoadWeb123(sender,args)
{
    //oList = web.get_lists().getByTitle('TimeSheetList');

    //clientContext.load(this.oList);
    //clientContext.executeQueryAsync(Function.createDelegate(this, this.LoadList), Function.createDelegate(this, this.onQueryFailed));   

}



function LoadList()
{
           var  camlQuery= new SP.CamlQuery();
                   camlQuery.set_viewXml("<View><Query><Where><And><And><Eq><FieldRef Name='Author'/><Value Type='User'>vikash kumar</Value></Eq><Geq><FieldRef Name='Date' /><Value Type='DateTime'>2015-07-10T12:00:00Z</Value></Geq></And><Leq><FieldRef Name='Date' /><Value Type='DateTime'>2015-07-17T12:00:00Z</Value></Leq></And></Where></Query></View>");  

   camlQuery.set_viewXml(camlQuery);

    this.collListItem = oList.getItems(camlQuery);


    clientContext.load(collListItem);
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));   

}


 function onQuerySucceeded(sender, args) {

    var listItemInfo = '';


    var listItemEnumerator = collListItem.getEnumerator();

    while (listItemEnumerator.moveNext()) {
                var oListItem = listItemEnumerator.get_current();
                var ID= oListItem.get_id();
                alert(ID);
                }
}


function onQueryFailed() {
//    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    alert('error');
}


</script>

<button type="button" onclick="retrieveListItems()">Approve!</button>

But this is not working, it gives error alert.

What could be done? Is there anything wrong with the code?

9
  • Where do you get the access denied error? Have you checked if you have at least read permissions to the list since you are only retrieving values?
    – Akhoy
    Jul 17, 2015 at 11:19
  • there is one ows.js file,in this file it is showing permission denied error when I am debugging the code in internet explorer. It is showing the first three alerts that I have given bt after that it is showing this permission denied error in ows.js file.
    – KumarV
    Jul 17, 2015 at 15:37
  • Which particular line in the above code fails? While getting the items, while getting the list? Where exactly?
    – Akhoy
    Jul 17, 2015 at 15:52
  • clientContext.load(oList); while debugging,it is not going to this code.
    – KumarV
    Jul 17, 2015 at 15:53
  • Check if you can access the list using: http://sharepointsite/_api/web/lists/getbytitle('TimeSheetList') in your browser.
    – Akhoy
    Jul 17, 2015 at 16:04

1 Answer 1

0

A small change in code and it worked..

<script type="text/javascript">
//var siteUrl = '/projects/';
var oList = null;
var web = null;
var clientContext  = null;



function retrieveListItems(sender, args) {

var filterValue =document.getElementById("ctl00_ctl41_g_1c91c2d4_fbbb_4792_8507_ba589e5be222_SpListPicker_SelectionBox");
var StartDate=document.getElementById("ctl00_ctl41_g_ed4beb82_8f7e_4389_bb35_a44188462aab_DateFilterPicker_DateFilterPickerDate");  
var EndDate=document.getElementById("ctl00_ctl41_g_07c2185d_e903_4010_8a84_b2d9536a5549_DateFilterPicker_DateFilterPickerDate");
alert(filterValue.value );
alert(StartDate.value);
alert(EndDate.value);


    clientContext = new SP.ClientContext.get_current();
    oList = clientContext.get_web().get_lists().getByTitle('TimeSheetList');
    clientContext.load(oList);

    clientContext.executeQueryAsync(Function.createDelegate(this, this.LoadList), Function.createDelegate(this, this.onQueryFailed));        


}



function LoadList(sender, args)
{
           var  camlQuery= new SP.CamlQuery();
           var query = "<View><Query><Where><Eq><FieldRef Name='Author' /><Value Type='User'>Vikash Kumar</Value></Eq></Where></Query></View>";
  camlQuery.set_viewXml(query);
    this.collListItem = oList.getItems(camlQuery);


    clientContext.load(collListItem);
    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));   

}


 function onQuerySucceeded(sender, args) {

     alert(collListItem.get_count());

    var listItemInfo = '';


    var listItemEnumerator = collListItem.getEnumerator();

    while (listItemEnumerator.moveNext()) {
                var oListItem = listItemEnumerator.get_current();
                var ID= oListItem.get_id();
                alert(ID);
                }
}


function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());

}


</script>

<button type="button" onclick="retrieveListItems()">button1!</button>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.