0

I would like to retrieve data from a list that has 2 columns but 4 fields.

Ex. I need the calculation from monthly & yearly cost from group 1 and calculations for monthly cost & yearly cost based on group 2.

I think some JavaScript should do the trick just don’t know where to start.

Please help.

1 Answer 1

0

This is easy done with JavaScript:

Retrieve Function will be something like this:

var siteUrl = '/sites/MySiteCollection';

function retrieveListItems() {

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

    var camlQuery = new SP.CamlQuery();
    camlQuery.set_viewXml('<View><Query><</Query></View>');
    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 group1Calculation=0;
        var group2Calculation=0;
        if(oListItem.get_item('groupName')=="Group1")
        {
            group1Calculation += parseInt(oListItem.get_item('monthly')) + parseint(oListItem.get_item('monthly'));
        }

        if(oListItem.get_item('groupName')=="Group2")
        {
            group2Calculation += parseInt(oListItem.get_item('monthly')) + parseint(oListItem.get_item('monthly'));
        }

    }

    alert(group1Calculation.toString());
    alert(group2Calculation.toString());
}

function onQueryFailed(sender, args) {

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

Your Answer

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

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