loadWorkGroupMultipleSelect=function(fieldId){
    $("#commonValidAlert").remove();
    var moduleId = $("#moduleId").val();
    var projectId=$("#projectId").val();
    var $input;
    var grid =$('#listingGrid').data("gridInstance1");
    var row = grid.getActiveCell().row;
    var cell = grid.getActiveCell().cell;
    if(fieldId =="wgservice"){
        var serviceSelecteddata=grid.getData()[row].wgservice;
        $.ajax({
            url: "getParentServicesList.do",
            type: "POST",
            dataType: 'json',
            async: false,
            data:"projectId="+projectId,
            success:function(result){
                $input=$("#wgservice");
                $input.empty();
                $(".select2-results__options").empty();

                $.each(result, function(key, value){
                    var selected = "";
                    if((","+serviceSelecteddata+",").indexOf(value.serviceName) != -1){
                        selected = "selected";
                    }
                    $input.append("<option value='"+value.serviceId+"' "+selected+">"+value.serviceName+"</option>");
                });
            }
        });
    }
    else if (fieldId == "category") {
        var categorySelecteddata=grid.getData()[row].category;
        $.ajax({
            url: "getCategoryList.do",
            type: "POST",
            dataType: 'json',
            async: false,
            data: "projectId=" + projectId, // Use an object to specify data
            success: function (result) {
                var $input = $("#category");
                $input.empty();
                $(".select2-results__options").empty();
                $.each(result, function (key, value) {
                    var selected = "";
                    if((","+categorySelecteddata+",").indexOf(value.categoryName) != -1){
                        selected = "selected";
                    }
                    $input.append("<option value='"+ value.categoryId+"' "+selected+">"+value.categoryName+"</option>");
                });
            }
        });
    }

    else if (fieldId == "wgsubCategory") {
        var subcategorySelecteddata=grid.getData()[row].wgsubCategory;
        var serviceSelectedIds=grid.getData()[row].wgserviceIds;
        $.ajax({
            url: "getSubCategories.do",
            type: "POST",
            dataType: 'json',
            async: false,
            data: "projectId=" + projectId +"&serviceIds="+serviceSelectedIds,
            success: function (result) {
                var $input = $("#wgsubCategory");
                $input.empty();
                $.each(result, function (key, value) {
                    var optGroup = $("<optgroup label='" + value.categoryLabel + "'>");
                    $.each(value.options, function (key1, value1) {
                        var selected = "";
                        if((","+subcategorySelecteddata+",").indexOf(value1.subCategoryName) != -1){
                            selected = "selected";
                        }
                        optGroup.append("<option value='" + value1.subCategoryID + "' "+selected+">" + value1.subCategoryName + "</option>");
                    });
                    $input.append(optGroup);
                });
            }
        });
    }
    else if(fieldId =="department"){
        var departmentSelecteddata=grid.getData()[row].department;
        $.ajax({
            url: "getDepartmentList.do",
            type: "POST",
            dataType: 'json',
            async: false,
            data:"projectId="+projectId,
            success:function(result){
                $input=$("#department");
                $input.empty();
                $(".select2-results__options").empty();
                $.each(result, function(key, value){
                    var selected = "";
                    if((","+departmentSelecteddata+",").indexOf(value.departmentName) != -1){
                        selected = "selected";
                    }
                    $input.append("<option value='"+value.departmentId+"' "+selected+">"+value.departmentName+"</option>");
                });
            }
        });
    }

    else if(fieldId =="workgroupRoles"){
        var workgroupRolesSelecteddata=grid.getData()[row].workgroupRoles;
        $.ajax({
            url: "getRoleList.do",
            type: "POST",
            dataType: 'json',
            async: false,
            data:"projectId="+projectId,
            success:function(result){
                $input=$("#workgroupRoles");
                $input.empty();
                $(".select2-results__options").empty();
                $.each(result, function(key, value){
                    var selected = "";
                    if((","+workgroupRolesSelecteddata+",").indexOf(value.roleName) != -1){
                        selected = "selected";
                    }
                    $input.append("<option value='"+value.roleId+"' "+selected+">"+value.roleName+"</option>");
                });
            }
        });
    }
                    }

$(document).on("click",".wgSingleSelectCell",function(){
    $(".wgSingleSelectCell select").on("select2:open", function()
    {
        var b=$(this).attr("id")
        loadWorkGroupSingleSelect(b);
    });
});

deleteWorkgroup= function(checkboxValues, projectId){
    var pageNumber=$("#listingGridPager").attr("data-pageno");
    var pageSize=$(".gridViewPort .recordLimit").val()
    var moduleId = $("#moduleId").val();
    var projectId = $("#projectId").val();
    $.ajax({
        url: "deleteSdWorkgroup.do",
        type: "POST",
        dataType: 'json',
        async: false,
        data: "workgroupList=" + checkboxValues + "&projectId=" + projectId,
        success: function (result) {
        },
        complete:function(){
            $("#listingGrid").before('<div class="sucessMsg" style="display: none;" id="success"><i class="ico statusIco"></i><p>${I18N_OBJECT.tr("Deleted successfully")} </p></div>');
        }
    });
    loadSdGridData(projectId,moduleId,pageNumber,pageSize,activeSortColumn,activeSortOrder);
}
loadWorkGroupSingleSelect=function(fieldId){
    var moduleId = $("#moduleId").val();
    var projectId=$("#projectId").val();
    var $input;
    if(fieldId =="workgroupStates"){
        $.ajax({
            url: "getWorkgroupStatesList.do",
            type: "POST",
            dataType: 'json',
            async: false,
            data:"projectId="+projectId,
            success:function(result){
                $input=$("#workgroupStates");
                $input.empty();
                $.each(result, function(key, value){
                    $input.append("<option value='"+value.statesId+"'>"+value.statesName+"</option>");
                });
            }
        });
    }
}
$(document).on("click",".showDerivedFieldsPop",function(eve){
    if(!$(eve.target).is(".showDerivedFieldsPop .expandDerivedFields,.showDerivedFieldsPop .collapseDerivedFields")){
        
        var grid =$('#listingGrid').data("gridInstance1");
        var row = grid.getActiveCell().row;
        var cell = grid.getActiveCell().cell;
        var workGroupId=grid.getData()[row].workgroupId;
        console.log("workGroupId"+workGroupId);
        var moduleId = $("#moduleId").val();
        var projectId=$("#projectId").val();
        $(".showDerivedFieldsPop").removeClass("opened");
        $(this).addClass("opened");
        $.ajax({
            url: "getWorkgroupDerivedFields.do",
            type: "POST",
            dataType: 'json',
            async: false,
            data: "projectId=" + projectId + "&workgroupId=" + workGroupId,
            success:function(result){
                
                var derivedField1Select = $("#derivedField1");
                var derivedField2Select = $("#derivedField2");
                var derivedField3Select = $("#derivedField3");

                derivedField1Select.empty();
                derivedField2Select.empty();
                derivedField3Select.empty();

                $.each(result[0].derivedFld1, function(index, item) {
                    if (result[0].derivedFld1SelectedId.includes(item.derivedFld1Name)){
                        derivedField1Select.append("<option id="+item.derivedFld1ID+" selected value='"+item.derivedFld1ID+"'>"+item.derivedFld1Name+"</option>");
                    }else{
                        derivedField1Select.append("<option id="+item.derivedFld1ID+" value='"+item.derivedFld1ID+"'>"+item.derivedFld1Name+"</option>");
                    }
                });

                $.each(result[0].derivedFld2, function(index, item) {
                    if (result[0].derivedFld2SelectedId.includes(item.derivedFld2Name)){
                        derivedField2Select.append("<option id="+item.derivedFld2ID+" selected value='"+item.derivedFld2ID+"'>"+item.derivedFld2Name+"</option>");
                    }else{
                        derivedField2Select.append("<option id="+item.derivedFld2ID+" value='"+item.derivedFld2ID+"'>"+item.derivedFld2Name+"</option>");
                    }
                });

                $.each(result[0].derivedFld3, function(index, item) {
                    if (result[0].derivedFld3SelectedId.includes(item.derivedFld3Name)){
                        derivedField3Select.append("<option id="+item.derivedFld3ID+" selected value='"+item.derivedFld3ID+"'>"+item.derivedFld3Name+"</option>");
                    }else{
                        derivedField3Select.append("<option id="+item.derivedFld3ID+" value='"+item.derivedFld3ID+"'>"+item.derivedFld3Name+"</option>");
                    }
                });
                $("#derivedField1, #derivedField2, #derivedField3").multipleSelect('refresh');

                if(result[0].considerCheckBox=="-1"){
                    $("#considerCheckBox").prop("checked", false);
                }else {
                    $("#considerCheckBox").prop("checked", true);
                }

            },complete:function(){
                var pos=$(".showDerivedFieldsPop.opened").position().left;
                $(".slick-viewport.slick-viewport-top.slick-viewport-right").scrollLeft(pos);
                $(".derivedFieldsDetails").show();
                $(".derivedFieldsDetails").position({
                    my: "left top",
                    at: "left top+30",
                    of: ".showDerivedFieldsPop.opened",
                    collision: "none"
                });
                if($("#considerCheckBox").prop("checked")==false){
                    $("#derivedField1,#derivedField2,#derivedField3").multipleSelect("disable");
                }else{
                    $("#derivedField1,#derivedField2,#derivedField3").multipleSelect("enable");
                }
            }
        });
    }
});
$(document).on("click","#closeDerivedFields,#cancelDerivedFlds",function(){
    $(".derivedFieldsDetails").hide();
    $(".showDerivedFieldsPop").removeClass("opened active");
});
$(document).on("change","#considerCheckBox",function(){
    if($(this).prop("checked")==false){
        $("#derivedField1,#derivedField2,#derivedField3").multipleSelect("disable");
    }else{
        $("#derivedField1,#derivedField2,#derivedField3").multipleSelect("enable");
    }
});
$(document).on("click","#saveDerivedFlds",function(){
    var df1=[];
    var df2=[];
    var df3=[];
    var urlParameters;
    var grid =$('#listingGrid').data("gridInstance1");
    var row = grid.getActiveCell().row;
    var cell = grid.getActiveCell().cell;
    var workGroupId=grid.getData()[row].workgroupId;
    
    console.log("workGroupId"+workGroupId);
    var moduleId = $("#moduleId").val();
    var projectId=$("#projectId").val();
    var pageNo=$("#listingGridPager").attr("data-pageno");
    var pageSize=$(".gridViewPort .recordLimit").val()
    if($("#considerCheckBox").prop("checked")==true && $("#derivedField1").val()=="" && $("#derivedField2").val()=="" && $("#derivedField3").val()==""){
        $("#derivedField1 + .ms-parent").after("<p class='fldErr' id='dfFldErr' style='bottom: 35px;'>Please choose derived fields</p>");
        return false;
    }
    if($("#considerCheckBox").prop("checked")==true){
        df1=$("#derivedField1").multipleSelect('getSelects');
        df2=$("#derivedField2").multipleSelect('getSelects');
        df3=$("#derivedField3").multipleSelect('getSelects');
        urlParameters="derivedfld1=" + df1 + "&derivedfld2=" + df2 + "&derivedfld3=" + df3;
    }else{
        urlParameters="derivedFlds="+0;
    }
    $.ajax({
        url: "saveDerivedFields.do",
        type: "POST",
        dataType: 'json',
        async: false,
        data: "projectId=" + projectId + "&workgroupId=" + workGroupId + "&" + urlParameters,
        success:function(result){

        },complete:function(){
            $(".showDerivedFieldsPop.opened span").text("Derived Field 1:"+df1+" Derived Field 2:"+df2+"Derived Field 3:"+df3);
            $("#closeDerivedFields").click();
        }
    });
    loadSdGridData(projectId, moduleId, pageNo, pageSize,activeSortColumn,activeSortOrder);
});
$(document).on("click",function(e){
    if(!$(e.target).is("#dfFldErr,#dfFldErr *")){
        $("#dfFldErr").remove();
    }
});

$(document).on("click",".readMoreData",function(e) {
    if($(this).hasClass("opened")==true){
        $("#readMoreBlk").hide();
        $(this).removeClass("opened");
    }else {
        $(".readMoreData").removeClass("opened");
        $(this).addClass("opened");
        var pos=$(".showDerivedFieldsPop.active").position().left;
        $(".slick-viewport.slick-viewport-top.slick-viewport-right").scrollLeft(pos);
        var moreData = $(this).prev("#decr").html();
        $("#readMoreBlk .loadedData").empty().append(moreData);
        $("#readMoreBlk").show();
        $("#readMoreBlk").position({
            my: "center+30 top",
            at: "left top+20",
            of: ".readMoreData.opened",
            collision: "none"
        });
    }
});
$(document).on("click",function(e){
    if(!$(e.target).is(".readMoreData,.readMoreBlk,.readMoreBlk *")){
        $("#readMoreBlk").hide();
        $(".readMoreData").removeClass("opened");
    }
});
saveWorkgroupDetails = function (workgroupId, field, projectId, dataToSave){
    var pageNo=$("#listingGridPager").attr("data-pageno");
    var pageSize=$(".gridViewPort .recordLimit").val()
    if(workgroupId == undefined){
        workgroupId = 0;
    }
    if(field=="workGroupName") {
        if(!isDoubleQuoteExists("workGroupName", dataToSave, "Work Group Name", "WorkGroupGridBlock")){
            return false;
        }
        if(workgroupId == 0){
            $.ajax({
                url: "checkDuplicateWorkgroupName.do",
                type: "POST",
                async: false,
                data: "projectId=" + projectId + "&workGroupName=" + dataToSave,
                success: function (result) {
                    if(result == 0){
                        saveWorkgroupName(workgroupId, projectId, field, dataToSave);
                    }else{
                        var grid =$('#listingGrid').data("gridInstance1");
                        var row = grid.getActiveCell().row;
                        var cell = grid.getActiveCell().cell;
                        grid.gotoCell(row, cell, true);
                        $(".slick-cell.active #workGroupName").addClass("redAlert");
                        $('#WorkGroupGridBlock').append('<p id="commonValidAlert" class="fldErr"><span class="topCurve"></span>Work Group Name already exists</p>');
                        $('#commonValidAlert').position({
                            my: "left top",
                            at: "left top+30",
                            of: ".redAlert",
                            collision: "none"
                        });
                        return false;
                    }
                }
            });
        }else {
            saveWorkgroupName(workgroupId, projectId, field, dataToSave);
        }
    }else if(field == "wgservice"){
        
        var pageNumber=$("#listingGridPager").attr("data-pageno");
        var pageSize=$(".gridViewPort .recordLimit").val()
        var moduleId = $("#moduleId").val();
        paramType=5;
        fieldParam="serviceList";
        $.ajax({
            url: "saveWorkgroupDetails.do",
            type: "POST",
            dataType: 'json',
            async: false,
            data: "workgroupId=" + workgroupId + "&projectId=" + projectId + "&parameterType=2&serviceIds=" + dataToSave,
            success: function (result) {

            }
        });
        loadSdGridData(projectId, moduleId, pageNo, pageSize,activeSortColumn,activeSortOrder);
    }else if(field == "category"){
        
        var pageNumber=$("#listingGridPager").attr("data-pageno");
        var pageSize=$(".gridViewPort .recordLimit").val()
        var moduleId = $("#moduleId").val();
        paramType=5;
        fieldParam="serviceList";
        $.ajax({
            url: "saveWorkgroupDetails.do",
            type: "POST",
            dataType: 'json',
            async: false,
            data: "workgroupId=" + workgroupId + "&projectId=" + projectId + "&parameterType=3&categoryIds=" + dataToSave,
            success: function (result) {

            }
        });
        loadSdGridData(projectId, moduleId, pageNo, pageSize,activeSortColumn,activeSortOrder);
    }else if(field == "wgsubCategory"){
        var pageNumber=$("#listingGridPager").attr("data-pageno");
        var pageSize=$(".gridViewPort .recordLimit").val()
        var moduleId = $("#moduleId").val();
        paramType=5;
        fieldParam="serviceList";
        $.ajax({
            url: "saveWorkgroupDetails.do",
            type: "POST",
            dataType: 'json',
            async: false,
            data: "workgroupId=" + workgroupId + "&projectId=" + projectId + "&parameterType=4&subCategoryIds=" + dataToSave,
            success: function (result) {

            }
        });
        loadSdGridData(projectId, moduleId, pageNo, pageSize,activeSortColumn,activeSortOrder);
    }else if(field == "location"){
        var pageNumber=$("#listingGridPager").attr("data-pageno");
        var pageSize=$(".gridViewPort .recordLimit").val()
        var moduleId = $("#moduleId").val();
        paramType=5;
        fieldParam="serviceList";
        $.ajax({
            url: "saveWorkgroupDetails.do",
            type: "POST",
            dataType: 'json',
            async: false,
            data: "workgroupId=" + workgroupId + "&projectId=" + projectId + "&parameterType=5&locationIds=" + dataToSave,
            success: function (result) {

            }
        });
        loadSdGridData(projectId, moduleId, pageNo, pageSize,activeSortColumn,activeSortOrder);
    }else if(field == "department"){
        var pageNumber=$("#listingGridPager").attr("data-pageno");
        var pageSize=$(".gridViewPort .recordLimit").val()
        var moduleId = $("#moduleId").val();
        paramType=5;
        fieldParam="serviceList";
        $.ajax({
            url: "saveWorkgroupDetails.do",
            type: "POST",
            dataType: 'json',
            async: false,
            data: "workgroupId=" + workgroupId + "&projectId=" + projectId + "&parameterType=6&departmentIds=" + dataToSave,
            success: function (result) {

            }
        });
        loadSdGridData(projectId, moduleId, pageNo, pageSize,activeSortColumn,activeSortOrder);
    }else if(field == "workgroupRoles"){
        var pageNumber=$("#listingGridPager").attr("data-pageno");
        var pageSize=$(".gridViewPort .recordLimit").val()
        var moduleId = $("#moduleId").val();
        paramType=5;
        fieldParam="serviceList";
        $.ajax({
            url: "saveWorkgroupDetails.do",
            type: "POST",
            dataType: 'json',
            async: false,
            data: "workgroupId=" + workgroupId + "&projectId=" + projectId + "&parameterType=7&roleIds=" + dataToSave,
            success: function (result) {

            }
        });
        loadSdGridData(projectId, moduleId, pageNo, pageSize,activeSortColumn,activeSortOrder);
    }else if(field == "workgroupUsers"){
        var pageNumber=$("#listingGridPager").attr("data-pageno");
        var pageSize=$(".gridViewPort .recordLimit").val()
        var moduleId = $("#moduleId").val();
        paramType=5;
        fieldParam="serviceList";
        $.ajax({
            url: "saveWorkgroupDetails.do",
            type: "POST",
            dataType: 'json',
            async: false,
            data: "workgroupId=" + workgroupId + "&projectId=" + projectId + "&parameterType=8&userIds=" + dataToSave,
            success: function (result) {

            }
        });
        loadSdGridData(projectId, moduleId, pageNo, pageSize,activeSortColumn,activeSortOrder);
    }else if(field == "workgroupStates"){
        var pageNumber=$("#listingGridPager").attr("data-pageno");
        var pageSize=$(".gridViewPort .recordLimit").val()
        var moduleId = $("#moduleId").val();
        paramType=5;
        fieldParam="serviceList";
        $.ajax({
            url: "saveWorkgroupDetails.do",
            type: "POST",
            dataType: 'json',
            async: false,
            data: "workgroupId=" + workgroupId + "&projectId=" + projectId + "&parameterType=9&stateIds=" + dataToSave,
            success: function (result) {

            }
        });
        loadSdGridData(projectId, moduleId, pageNo, pageSize,activeSortColumn,activeSortOrder);
    }else if(field == "functionalEscalation"){
        var pageNumber=$("#listingGridPager").attr("data-pageno");
        var pageSize=$(".gridViewPort .recordLimit").val()
        var moduleId = $("#moduleId").val();
        paramType=5;
        fieldParam="serviceList";
        $.ajax({
            url: "saveWorkgroupDetails.do",
            type: "POST",
            dataType: 'json',
            async: false,
            data: "workgroupId=" + workgroupId + "&projectId=" + projectId + "&parameterType=10&functionalEscalation=" + dataToSave,
            success: function (result) {

            }
        });
        loadSdGridData(projectId, moduleId, pageNo, pageSize,activeSortColumn,activeSortOrder);
    }else if(field == "removeOwner"){
        var pageNumber=$("#listingGridPager").attr("data-pageno");
        var pageSize=$(".gridViewPort .recordLimit").val()
        var moduleId = $("#moduleId").val();
        paramType=5;
        fieldParam="serviceList";
        $.ajax({
            url: "saveWorkgroupDetails.do",
            type: "POST",
            dataType: 'json',
            async: false,
            data: "workgroupId=" + workgroupId + "&projectId=" + projectId + "&parameterType=11&removeOwner=" + dataToSave,
            success: function (result) {

            }
        });
        loadSdGridData(projectId, moduleId, pageNo, pageSize,activeSortColumn,activeSortOrder);
    }
}
saveWorkgroupName = function(workgroupId, projectId, field, dataToSave){
    var newID;
    $.ajax({
        url: "saveSdWorkgoupName.do",
        type: "POST",
        dataType: 'json',
        async: false,
        data: "workgroupId=" + workgroupId + "&projectId=" + projectId + "&" + field + "=" + dataToSave,
        success: function (result) {
            if(workgroupId==0){
                newID=result;
            }
        },complete:function(){
            var grid =$('#listingGrid').data("gridInstance1");
            var row = grid.getActiveCell().row;
            var data=grid.getData();
            if(workgroupId==0){
                data[row].workgroupId=newID;
            }
            if(data[row][10]==undefined && data[row][10]==undefined){
                grid.gotoCell(row, 10, true);
                $(".wgSelectCell.active").addClass("redAlert");
                var pos=$(".wgSelectCell.redAlert").position().left;
                $(".slick-viewport.slick-viewport-top.slick-viewport-right").scrollLeft(pos);
                $('#WorkGroupGridBlock').append('<p id="commonValidAlert" class="fldErr mand"><span class="topCurve"></span>Please select atleast one role or user</p>');
                $('#commonValidAlert').position({
                    my: "left top",
                    at: "left top+30",
                    of: ".redAlert",
                    collision: "none"
                });
            }
            $("#listingGrid .slick-viewport.ps-container").perfectScrollbar("destroy");
        }
    });
}
$(document).on("click", "#WorkGroupGridBlock .saveDes", function () {
    var desc = CKEDITOR.instances['workGroupDesc'].getData();
    $(currSelectedcell).html(desc);
    var alteredRow = $(".slick-row.active").index();
    var gridSlick = $("#listingGrid").data("gridInstance1");
    var dataToSave = gridSlick.getDataItem(alteredRow);
    var projectId = $("#projectId").val();
    if(desc.length > 512){
        validationAlertShown=true;
        $('#cke_workGroupDesc').addClass("redAlert");
        $('#cke_workGroupDesc').append('<p id="commonValidAlert" class="fldErr" style="bottom:15px"><span class="topCurve"></span>Please limit your Description content less than or equal to 512 characters</p>');
        $('#commonValidAlert').show();
        return false;
    }
    $.ajax({
        url:"saveWorkgroupDetails.do",//"saveSdWorkGroupDescription.do",
        type: "POST",
        dataType: 'json',
        async: false,
        data: "workgroupId=" + dataToSave.workgroupId + "&projectId=" + projectId + "&parameterType=1&specializationDesc=" + encodeURIComponent(desc),
        success: function (result) {
        }
    });
    $(".descriptionBlk #workGroupDesc,.descriptionBlk .saveDes,.descriptionBlk .cancelDes,.descriptionBlk .closeBlk").remove();
    CKEDITOR.instances["workGroupDesc"].destroy();
    $(".descBlkOverlay,.descriptionBlk").hide();
    $(".ckEditorCol").removeClass("clicked");
    var pageNo = $("#listingGridPager").attr("data-pageno");
    var pageSize = $("#recordLimit4[name='recordLimit4']").val();
    var moduleId = $("#moduleId").val();
    loadSdGridData(projectId,moduleId,pageNo,pageSize,activeSortColumn,activeSortOrder);
});
var collapseDataSetObject = {};
var historyId;
$(document).on("click", "#WorkGroupGridBlock .expandDerivedFields", function (e)
{
    var isGridWithCollapse=false;
    $("#cancelDerivedFlds").click();
    var projectId = $(this).attr("data-projectId");
    var slickGrid = $("#listingGrid").data("gridInstance1");
    var dynamicAttributes = ["workgroupId", "workGroupName", "workGroupDesc", "service", "category","subCategory","location","department","derivedFields","functionalEscalation","workgroupRoles","workgroupUsers","workgroupStates","removeOwner"];
    var row=$(".slick-row.active").index();
    var dataToSave=slickGrid.getData(row);
    var grid =$('#listingGrid').data("gridInstance1");
    var row = grid.getActiveCell().row;
    var cell = grid.getActiveCell().cell;
    var workGroupId=grid.getData()[row].workgroupId;
    console.log("workGroupIdexpand--"+workGroupId);
    $.ajax({
        url: "getWorkgroupExpandDerivedFields.do",
        type: "POST",
        dataType: 'json',
        async: false,
        data:"workgroupId=" + workGroupId,
        success:function(result){
            var data = slickGrid.getData();
            for (var j=data.length-1; j>=0; j--){
                if(data[j].workgroupId==""){
                    isGridWithCollapse=true;
                    data = data.filter(function(elem){
                        slickGrid.invalidateRow(j);
                        row=$(".slick-row.active").index();
                        return elem != data[j];
                    })
                }
            }
            var newrow;
            var dataLength = data.length;
            var j=0;
            for (var i =result.length-1; i>=0; i--)
            {
                var indiData = result[i];
                indiData["id"] = "history" + (j + dataLength);
                indiData["historyId"] = "" + dataToSave.workflowId;
                newrow = jQuery.extend(dynamicAttributes, indiData);
                data.splice(row + 1, 0, indiData);
                j++;
            }
            slickGrid.setData(data);
            var totRows=data.length;
            var totHeight=(totRows+1)*30;
            $("#listingGrid").css("height",""+totHeight+"px");
            slickGrid.resizeCanvas();
        },complete:function(){
            var newRowEnd=row+4;
            for(i=row+2;i<=newRowEnd;i++){
                $(".slick-row:nth-child("+i+") .slick-cell").addClass("disabled expandedData");
                $(".slick-cell.expandedData.slick-cell-checkboxsel input[type=checkbox]").remove();
                $(".slick-cell.expandedData .expandDerivedFields").remove();
                $(".slick-cell.expandedData").removeClass("showDerivedFieldsWorkflowPop");
            }
            collapseDataSetObject["expandHistoryIco"+dataToSave.workflowId] = "collapseIco";
            if(isGridWithCollapse==true){
                row=row+1;
                $(".slick-row:nth-child("+row+")").find(".expandDerivedFields").addClass("collapseDerivedFields").removeClass("expandDerivedFields");
            }else{
                $(".slick-row.active").find(".expandDerivedFields").addClass("collapseDerivedFields").removeClass("expandDerivedFields");
            }
            $(".collapseDerivedFields").text("-");
            e.preventDefault();
        }
    });
});

$(document).on("click", "#WorkGroupGridBlock .collapseDerivedFields", function (e)
{
    var isRowFound=-1;
    collapseDataSetObject["expandHistoryIco"+historyId] = "expandIco";
    var slickGrid = $("#listingGrid").data("gridInstance1");
    var data = slickGrid.getData();
    var dataLength = data.length;
    var row=$(".slick-row.active").index();
    var dataToSave=slickGrid.getData(row);
    var checkedRows = [];
    
    for (var i =row; i<dataLength ; i++)
    {
        var indiData = data[i];
        if (indiData.historyId!=undefined)
        {
            if(isRowFound==-1){
                isRowFound=i;
            }
            checkedRows.push(i);

        }
    }
    data.splice(isRowFound,3);
    for (var rowLength = 0; rowLength < checkedRows.length; rowLength++)
    {
        slickGrid.invalidateRow(checkedRows[rowLength]);
        slickGrid.setData(data);
        slickGrid.updateRowCount();
        var totRows=data.length;
        var totHeight=(totRows+1)*30;
        $("#listingGrid").css("height",""+totHeight+"px");
        slickGrid.resizeCanvas();
        slickGrid.render();
        dataLength = dataLength - 1;
        slickGrid.scrollRowIntoView(dataLength);
    }
    $(".slick-row.active").find(".collapseDerivedFields").addClass("expandDerivedFields").removeClass("collapseDerivedFields");
    $(".expandDerivedFields").text("+");
    e.preventDefault();
});