0

The short story is I want to open a custom filtered view created by the standard SP UI and click a button that will iterate through all the items in the view and change the status field to complete. Is this possible using JavaScript and the standard (caml query?) that's built into the view itself. The code below is from the allitems.aspx view from my test list.

<XmlDefinition>
        <View Name="{18305BB9-22DA-4BC2-8A05-F114008FA2A5}" DefaultView="TRUE" MobileView="TRUE" MobileDefaultView="TRUE" Type="HTML" DisplayName="All Items" Url="/sites/Test/subsite/Lists/Test/AllItems.aspx" Level="1" BaseViewID="1" ContentTypeID="0x" ImageUrl="/_layouts/images/generic.png">
            <Query>
                <OrderBy>
                    <FieldRef Name="ID"/>
                </OrderBy>
            </Query>
            <ViewFields>
                <FieldRef Name="ID"/>
                <FieldRef Name="LinkTitle"/>
                <FieldRef Name="Status"/>
            </ViewFields>
            <RowLimit Paged="TRUE">30</RowLimit>
            <Aggregations Value="Off"/>
            <Toolbar Type="Standard"/>
        </View>
    </XmlDefinition>

I'll be using using a CEWP. I'm familiar with programming concepts (looping, selection statements, etc). What's killing me is the lack of knowledge pertaining to SP syntax and the available methods I could use. Any help will be appreciated.Thanks.

0

Yes you can use caml query in ecma. The example that you need:

var siteUrl = 'your site collection url';
var collListItem ='';
function retrieveListItems() {

    var clientContext = new SP.ClientContext(siteUrl);
    var oList = clientContext.get_web().get_lists().getByTitle('your list name');

    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('your caml 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) {

    var listItemEnumerator = collListItem.getEnumerator();

    while (listItemEnumerator.moveNext()) {
        var oListItem = listItemEnumerator.get_current();
       oListItem.set_item('Status', 'Complete');
       oListItem.update();
       context.executeQueryAsync(Function.createDelegate(this, this.success), Function.createDelegate(this, this.failed));
    }

}

function onQueryFailed(sender, args) {

    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
}

Link to MSDN

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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