Quantcast
Channel: SharePoint 2013 - General Discussions and Questions forum
Viewing all articles
Browse latest Browse all 26374

Multiple Group By using two look-up columns which have multi valued selection enabled on an SP 2013 list using JavaScript.

$
0
0

Hi All,

So I'm working on SP 2013 and have a document library which has three Lookup columns viz : Business Unit, Axis Product and Policy form. What I'm trying to do is I have managed to group by the List items first by Business Unit column and then by the Axis Product Column. This works fine but recently I'm trying to show the count of the number of items inside a particular Axis Product. Which would be like - Axis Product : "Some Value" (Count).

I'm able to show this count with Business Unit, but not able to do this with Axis Product. So I tried querying the library with both Business Unit and Axis Product to get the count for Axis Product, I'm not sure about this approach and currently I'm getting an error message - "'collListItemAxisProduct' is undefined" . Any help would be appreciated as I've been stuck on this for a long time now. Here is my code below :

// JavaScript source code

$(function () {

    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', oGroupBy.GetDataFromList);

});

 

 

 

 

function GroupBy()

{

    this.clientContext = "";

    this.SiteUrl = "/sites/insurance/products";

    this.lookUpLIst = "AxisBusinessUnit";

    this.AxisProductlookUpList = "AXIS Product";

    this.lookUpItems = [];

    this.lookUpColumnName = "Title";

    this.AxisProductlookupItems = [];

 

    this.AProducts = [];

    this.index = 0;

    this.secondindex = 0;

    this.parentList = "AXIS Rules Library";

    this.html = "<div id='accordion'><table cellspacing='35' width='100%'><tr><td width='8%'>Edit</td><td width='13%'>Name</td><td width='13%'>Modified</td><td width='13%'>Underwriting Comments</td><td width='13%'>Policy Form Applicability</td><td width='13%'>AXIS Product</td><td width='13%'>Business Unit</td></tr>";

}

function MultipleGroupBy()

{

    this.AxProducts = [];

    this.SecondaryGroupBy = [];

    this.count = "";

    this.BusinessUnit = "";

    this.html = "";

}

function UI()

{

    this.id = "";

    this.name = "";

    this.modified = "";

    this.acturialComments = "";

    this.underWritingComments = "";

    this.policyFormApplicability = [];

    this.axisProduct = [];

    this.businessUnit = [];

    this.itemcheck = "";

    this.Count = 0;

    this.header = "";

    this.AxisProductCount = 0;

    this.trID = "";

    this.SecondaryID = "";

    this.LandingUrl = "&Source=http%3A%2F%2Fecm%2Ddev%2Fsites%2FInsurance%2FProducts%2FAXIS%2520Rules%2520Library%2FForms%2FGroupBy%2Easpx";

 

 

}

var oUI = new UI();

var oGroupBy = new GroupBy();

var oMultipleGroupBy = new MultipleGroupBy();

GroupBy.prototype.GetDataFromList = function () {

 

 

    oGroupBy.clientContext = new SP.ClientContext(oGroupBy.SiteUrl);

    var oList = oGroupBy.clientContext.get_web().get_lists().getByTitle(oGroupBy.lookUpLIst);

    var APList = oGroupBy.clientContext.get_web().get_lists().getByTitle(oGroupBy.AxisProductlookUpList);

    var camlQuery = new SP.CamlQuery();      

    this.collListItem = oList.getItems(camlQuery);

    var secondcamlQuery = new SP.CamlQuery();

    this.secondListItem = APList.getItems(secondcamlQuery);

    oGroupBy.clientContext.load(collListItem);

    oGroupBy.clientContext.load(secondListItem);

   oGroupBy.clientContext.executeQueryAsync(Function.createDelegate(this, oGroupBy.BindDataFromlookUpList), Function.createDelegate(this, oGroupBy.onError));

 

 

}

 

GroupBy.prototype.BindDataFromlookUpList = function (seneder,args) {

 

    var listenumerator = collListItem.getEnumerator();

 

    while (listenumerator.moveNext()) {

        var currentitem = listenumerator.get_current();

        oGroupBy.lookUpItems.push(currentitem.get_item(oGroupBy.lookUpColumnName));

    }

    oGroupBy.GetDataFromParent(oGroupBy.lookUpItems);

}

 

 

 

GroupBy.prototype.GetDataFromParent = function(lookUpItems)

{

        var oList1 = oGroupBy.clientContext.get_web().get_lists().getByTitle(oGroupBy.parentList);

        var camlQuery = new SP.CamlQuery();

 

        camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name=\'Business_x0020_Unit\'/>' +

            '<Value Type=\'LookupMulti\'>' + oGroupBy.lookUpItems[oGroupBy.index] + '</Value></Eq></Where></Query></View>');

 

        this.collListItem1 = oList1.getItems(camlQuery);

 

        oGroupBy.clientContext.load(this.collListItem1, 'Include(ID, Business_x0020_Unit, Title, FileLeafRef, ModifiedDate, Policy_x0020_Form_x0020_Applicability, AXIS_x0020_Product, Underwriting_x0020_Comments)');

        oGroupBy.clientContext.executeQueryAsync(Function.createDelegate(this, oGroupBy.CreateHTMLGroupBy), Function.createDelegate(this, oGroupBy.onError));

 

 

}

GroupBy.prototype.CreateHTMLGroupBy = function (sender,args)

{

 

    var listenumerator = this.collListItem1.getEnumerator();

    var axisproductlistenumarator = secondListItem.getEnumerator();

    while (axisproductlistenumarator.moveNext()) {

        var currentitem = axisproductlistenumarator.get_current();

        oGroupBy.AxisProductlookupItems.push(currentitem.get_item(oGroupBy.lookUpColumnName));

    }

    enter code here

    oUI.Count = this.collListItem1.get_count();

    if (oGroupBy.lookUpItems[oGroupBy.index] != undefined && oUI.Count > 0) {

        oUI.trID = oGroupBy.lookUpItems[oGroupBy.index];

        oMultipleGroupBy.BusinessUnit = oGroupBy.lookUpItems[oGroupBy.index];

        oGroupBy.html = oGroupBy.html + "<table style='cursor:pointer' id='" + oUI.trID.replace(" ", "") + "' onclick='javascript:oUI.Slider(this.id)'><tr><td colspan='7'><h2 style='width:1100px;font-weight: bold;border-bottom:1px solid #888888;padding:5px;'>Business Unit : " + oGroupBy.lookUpItems[oGroupBy.index] + "  " + "<span> (" + oUI.Count + ")</span></h2></td></tr></table>";

 

   }

 

    oUI.businessUnit.length = 0;

    oMultipleGroupBy.SecondaryGroupBy.length = 0;

    oMultipleGroupBy.SecondaryGroupBy.push(oUI.trID);

    oMultipleGroupBy.html = "";

 

 

    if (oUI.Count > 0) {

        if (listenumerator != undefined) {

            while (listenumerator.moveNext()) {

                var currentitem = listenumerator.get_current();

                if (currentitem != undefined) {

                    oUI.id = currentitem.get_item("ID");

                    oUI.name = currentitem.get_item("FileLeafRef");

                    oUI.modified = currentitem.get_item("ModifiedDate");

                    //oUI.policyFormApplicability = currentitem.get_item("Policy_x0020_Form_x0020_Applicability");

                    oUI.underWritingComments = currentitem.get_item("Underwriting_x0020_Comments");

                    //oUI.axisProduct = currentitem.get_item("AXIS_x0020_Product");

                    var lookupPolicyFormApplicability = currentitem.get_item("Policy_x0020_Form_x0020_Applicability");

                    var lookupField = currentitem.get_item("Business_x0020_Unit");

                    var lookupAxisProduct = currentitem.get_item("AXIS_x0020_Product");

 

 

                    oUI.businessUnit.length = 0;

                    for (var i = 0; i < lookupField.length; i++) {

                        oUI.businessUnit.push(lookupField[i].get_lookupValue());

                    }

 

                    oUI.axisProduct.length = 0;

                    for (var m = 0; m < lookupAxisProduct.length; m++) {

                        oUI.axisProduct.push(lookupAxisProduct[m].get_lookupValue());

 

                    }

 

 

                    oUI.policyFormApplicability.length = 0;

                    for (var a = 0; a < lookupPolicyFormApplicability.length; a++)

                    {

                        oUI.policyFormApplicability.push(lookupPolicyFormApplicability[a].get_lookupValue());

                    }

 

 

 

                    oGroupBy.CreateUI(oUI);

                }

            }

            if (oGroupBy.lookUpItems[oGroupBy.index] != undefined && oUI.Count > 0) {

                    oGroupBy.html = oGroupBy.html + oMultipleGroupBy.html;

            }

        }

    }

 

    oGroupBy.index = oGroupBy.index + 1;

    if (oGroupBy.index <= oGroupBy.lookUpItems.length) {

        oGroupBy.GetDataFromParent(oGroupBy.lookUpItems);

    }

 

 

 

    if(oGroupBy.index == oGroupBy.lookUpItems.length + 1)

    {

 

        oGroupBy.html = oGroupBy.html + "</table></div>";

 

        $("#contentBox").append(oGroupBy.html);

        $(".hide,.sd-hide").hide();

 

    }

}

 

UI.prototype.Slider = function (id) {

 

    $("#MSOZoneCell_WebPartWPQ3").click();

    //$(".hide").hide();

    var elements = document.querySelectorAll('[data-show="' + id + '"]');

 

    $(elements).slideToggle();

}

UI.prototype.SecondarySlider = function (id) {

    var elements = document.querySelectorAll('[data-secondary="' + id + '"]');

    $(elements).slideToggle();

}

 

 

GroupBy.prototype.CreateUI = function (oUI) {

    var BusinessUnit = "";

    var AxisProduct = "";

    var Policyformapplicability = "";

    var tempBUnit = "";

    for (var i = 0; i < oUI.businessUnit.length; i++) {

        BusinessUnit = BusinessUnit + oUI.businessUnit[i] + ",";

    }

    for (var m = 0; m < oUI.axisProduct.length; m++) {

        AxisProduct = AxisProduct + oUI.axisProduct[m] + ",";

    }

 

 

    for (var a = 0; a < oUI.policyFormApplicability.length; a++) {

        Policyformapplicability = Policyformapplicability + oUI.policyFormApplicability[a] + ",";

    }

    oGroupBy.clientContext = new SP.ClientContext(oGroupBy.SiteUrl);

    var oList1SecondGroupBy = oGroupBy.clientContext.get_web().get_lists().getByTitle(oGroupBy.parentList);

    var camlQuery = new SP.CamlQuery();

 

    camlQuery.set_viewXml('<View><Query><Where><And><Eq><FieldRef Name=\'Business_x0020_Unit\' /><Value Type=\'LookupMulti\'>' + oGroupBy.lookUpItems[oGroupBy.index] + '</Value></Eq>'+

    '<Eq><FieldRef Name=\'AXIS_x0020_Product\' /><Value Type=\'LookupMulti\'>' + oGroupBy.AxisProductlookupItems[oGroupBy.secondindex] + '</Value></Eq></And></Where><OrderBy><FieldRef Name=\'Title\' Ascending=\'True\' /></OrderBy></Query><View>');

    this.collListItemAxisProduct = oList1SecondGroupBy.getItems(camlQuery);

    oGroupBy.clientContext.load(this.collListItemAxisProduct, 'Include(ID, Business_x0020_Unit, Title, FileLeafRef, ModifiedDate, Policy_x0020_Form_x0020_Applicability, AXIS_x0020_Product, Underwriting_x0020_Comments)');

    if (collListItemAxisProduct != undefined) {

        //oGroupBy.clientContext.load(collListItemAxisProduct);

        var AxisProductlistenumerator = this.collListItemAxisProduct.getEnumerator();

 

 

        if (AxisProductlistenumerator != undefined) {

            oUI.AxisProductCount = this.collListItemAxisProduct.get_count();

            oGroupBy.AProducts.length = 0;

            if (AxisProduct != "") {

                oGroupBy.AProducts = AxisProduct.split(',');

            }

            oGroupBy.AProducts.splice(oGroupBy.AProducts.length - 1, 1);

            //alert(oGroupBy.AProducts.length);

 

 

            var link = "/sites/Insurance/Products/AXIS%20Rules%20Library/Forms/EditForm.aspx?ID=" + oUI.id + oUI.LandingUrl;

            var editicon = "/sites/insurance/products/_layouts/15/images/edititem.gif?rev=23";

 

 

 

 

            for (var i = 0; i < oGroupBy.AProducts.length; i++) {

 

 

                var SecondaryGBTableID = "";

 

 

                if (oGroupBy.AProducts[i].replace(" ", "") != "") {

 

                    SecondaryGBTableID = oGroupBy.AProducts[i].replace(/\s/g, "") + oMultipleGroupBy.BusinessUnit.replace(/\s/g, "");

                    SecondaryGBTableID = SecondaryGBTableID.replace("&", "");

                    var isPresent = $.inArray(oGroupBy.AProducts[i].replace(/\s/g, ""), oMultipleGroupBy.SecondaryGroupBy);

                }

 

                oUI.SecondaryID = oUI.trID.replace("/\s/g", "") + oGroupBy.AProducts[i].replace("/\s/g", "");

 

 

                if ((isPresent <= -1)) {

 

 

                    oMultipleGroupBy.html = oMultipleGroupBy.html + "<tr style='margin-margin-bottom:1px solid grey;' cellspacing='36'><td ><h3  class='hide' onclick='javascript:oUI.SecondarySlider(this.id);' id='" + oUI.SecondaryID + "' data-show='" + oUI.trID.replace(" ", "") + "'  style='cursor:pointer;width:100%;font-weight: bold;border-bottom:1px solid #888888;padding:5px;'>&#160;&#160;&#160;&#160;-&#160;&#160;&#160;AXIS Product : " + oGroupBy.AProducts[i] + "  " + "<span> (" + oUI.AxisProductCount + ")</span></h3></td></tr>";

                    oMultipleGroupBy.html = oMultipleGroupBy.html + "<tr><td><table  class='hide'  data-show='" + oUI.trID.replace(" ", "") + "'  width='100%' cellspacing='36' id='" + SecondaryGBTableID + "'><tr class='sd-hide' data-secondary='" + oUI.SecondaryID + "'><td width='8%'><a href='" + link + "'><img src='" + editicon + "'></a></td><td width='13%'><a href='/sites/Insurance/Products/AXIS%20Rules%20Library/" + oUI.name + "' target='_self'>" + oUI.name.replace(/\.[^/.]+$/, "") + "</a></td><td width='13%'>" + oUI.modified + "</td><td width='13%'>" + oUI.underWritingComments + "</td><td width='13%'>" + oUI.policyFormApplicability + "</td><td width='13%'>" + oUI.axisProduct+ "</td><td width='13%'>" + oUI.businessUnit + "</td></tr></table></td></tr>";

                }

                else {

                   if ($("#" + SecondaryGBTableID).html() != undefined) {

 

 

                        $("#" + SecondaryGBTableID).append("<tr class='sd-hide' data-secondary='" + oUI.SecondaryID + "'><td width='8%'><a href='" + link + "'><img src='" + editicon + "'></a></td><td width='13%'><a href='/sites/Insurance/Products/AXIS%20Rules%20Library/" + oUI.name + "' target='_self'>" + oUI.name.replace(/\.[^/.]+$/, "")+ "</a></td><td width='13%'>" + oUI.modified + "</td><td width='13%'>" + oUI.underWritingComments + "</td><td width='13%'>" + oUI.policyFormApplicability +"</td><td width='13%'>" + oUI.axisProduct + "</td><td width='13%'>" + oUI.businessUnit + "</td></tr>");

                        oMultipleGroupBy.html = $("#divMultiplegroupBy").html();

                    }

                }

                document.getElementById("divMultiplegroupBy").innerHTML = oMultipleGroupBy.html;

 

                if ((isPresent <= -1) && (oGroupBy.AProducts[i] != "")) {

                    oMultipleGroupBy.SecondaryGroupBy.push(oGroupBy.AProducts[i].replace(/\s/g, ""));

                }

            }

        }

    }

    else {

        oGroupBy.secondindex = oGroupBy.secondindex + 1;

        oGroupBy.CreateUI(oUI);

    }

}

GroupBy.prototype.onError = function (sender, args) {

    alert('Error: ' + args.get_message() + '\n');

}

Regards,

Rivin Jose


Viewing all articles
Browse latest Browse all 26374

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>