Friday, 13 September 2019

KendoUI filterable display internal error status:500

I am currently making some modifications on an application developed by someone else. The application uses the KendUI to render data on a grid. By default, the assumption would have been that the grid should be able to do filters and sort. When I turned the grid filters on and chose specific fields to filter by, I get status 500 error;

GET http://localhost/RFG/Workpermits?take=10&skip=0&page=1&pageSize=10&filter%5Blogic%5D=and&filter%5Bfilters%5D%5B0%5D%5Bfield%5D=Id&filter%5Bfilters%5D%5B0%5D%5Boperator%5D=eq&filter%5Bfilters%5D%5B0%5D%5Bvalue%5D=7&filter%5Bfilters%5D%5B1%5D%5Bfield%5D=ContractorName&filter%5Bfilters%5D%5B1%5D%5Boperator%5D=contains&filter%5Bfilters%5D%5B1%5D%5Bvalue%5D=Sor 500 (Internal Server Error)

Here is the piece of codes being used.

var workPermitsListView = new WorkPermitsListView();

$(document).ready(function () {   
        
        

    workPermitsListView.initializeControls();  
        
        var kgrid = $("#workPermitsGrid").data("kendoGrid");
        var oldOptions = kgrid.getOptions();
      
    var options = localStorage["kendo-grid-options"];   
    if (options) {
                var savedOptions = JSON.parse(options);
                var editFunc = oldOptions.columns[0];
                savedOptions.columns[0] = editFunc;
        kgrid.setOptions(savedOptions);         
                kgrid.dataSource.read();
                
     }                  
          
});

function WorkPermitsListView() {

    this.initializeControls = function () {

        var url = window.location.href.slice(window.location.href.indexOf('?') + 1);

        if (url == "refresh=true") {
            window.location = window.location;
            window.location = "WorkPermitsList.aspx";
        } else if (url == "refresh=false") {
            window.location = window.location;
        }

        $("#addWorkPermitBtn").on("click", function (e) { e.preventDefault(); workPermitsListView.createNewWorkPermit(); });
        $("#omniSearchAdvTxt").keypress(function (e) { if (e.keyCode === 13) { $("#advSearchWorkPermitBtn").click(); } });
        $("#omniSearchWorkPermitID").keypress(function (e) { if (e.keyCode === 13) { $("#advSearchWorkPermitBtn").click(); } });
        $("#omniSearchLocation").keypress(function (e) { if (e.keyCode === 13) { $("#advSearchWorkPermitBtn").click(); } });

       // $("#addWorkPermitBtn").kendoButton().data("kendoButton").enable(secScriptObj.canWriteWorkPermit);

        if (!secScriptObj.canWriteWorkPermit) {
            $("#addWorkPermitBtn").hide();
        }
        else {
            $("#addWorkPermitBtn").kendoButton().data("kendoButton").visible = true;
            $("#addWorkPermitBtn").kendoButton().data("kendoButton").enable(secScriptObj.canWriteWorkPermit);
        }        

        var gridDefaultActionName = secScriptObj.canWriteWorkPermit ? "Edit" : "View";

        var gridDataSource = new kendo.data.DataSource(
            {
                transport: { read: PTWApp.getSitePrefix() + "/Workpermits" },
                pageSize: 10,
                serverPaging: true,
                serverFiltering: true,
                serverSorting: true,
                schema: {
                    total: "total",
                    data: "data",
                    model: {
                        id: "Id"
                    }
                }
            }
        );
                
                //var options = localStorage["grid-options"];

        $("#workPermitsGrid").kendoGrid({
            autoBind: false,
            dataSource: gridDataSource,
            scrollable: true,
            sortable: true,
                        dataBound: WorkPermitsListView.onDataBind,
            pageable: {
                input: true,
                numeric: false
            },
            noRecords: { template: "<div class='noRecordsDiv'>No permits to display. Use search for more or contact the administrator for assistance.</div>" },
            filterable: true,
                        schema:{
                                model:{
                                        fields:{
                                                Id:{type:"int"},
                                                StartDate:{type:"date"},
                                                EndDate:{type:"date"}
                                        }
                                }
                        },
            
            columns: [
                {
                    command: {
                        click: WorkPermitsListView.editWorkPermit,
                        name: "modify",
                        text: gridDefaultActionName
                    },
                    width: "70px"
                },
                {
                    field: "Id",
                    title: "Permit #",
                    width: "7%" , 
                                        headerAttributes: { style: "white-space: normal"}
                },
                {
                    field: "Status",
                    title: "Status",
                    template: "#= WorkPermitsListView.addStatusImg(data)#",
                    width: "7%",
                                        filterable:false,
                                        headerAttributes: { style: "white-space: normal"},
                    editor: workPermitsListView.selectPermit
                },
                {
                    field: "StartDate",
                    title: "Start Date",
                    template: "#= PTWApp.ConvertDate(data.StartDate)#",
                    width: "7.5%",
                                        filterable:false,
                                        headerAttributes: { style: "white-space: normal"}
                },
                {
                    field: "EndDate",
                    title: "End Date",
                    template: "#= PTWApp.ConvertDate(data.EndDate)#",
                    width: "7.5%",
                                        filterable:false,
                                        format:"{0:MMM dd yyyy}",
                                        headerAttributes: { style: "white-space: normal"}
                },
                {
                    field: "ContractorName",
                    title: "Contractor",
                    width: "8.5%",
                                        
                                        headerAttributes: { style: "white-space: normal"}
                },
                {
                    field: "ContractorSupervisorName",
                    title: "Supervisor",
                    width: "8.5%",
                                        filterable:false,
                                        headerAttributes: { style: "white-space: normal"}
                },
                {
                    field: "ContractorSupervisorPhone",
                    title: "Phone #",
                    template: "#: WorkPermitsListView.formatPhone(ContractorSupervisorPhone) #",
                    width: "7.5%",
                                        filterable:false,
                                        headerAttributes: { style: "white-space: normal"}
                },
                {
                    field: "RequestedBy",
                    title: "Requester",
                    width: "7.5%",
                                        filterable:false
                },
                                {
                    field: "Attachments",
                    title: "Files",
                    template: "#= WorkPermitsListView.addFileImg(data)#",
                                        filterable:false,
                    width: "6%"
                                        
                },
                {
                    field: "IsEvent",
                    title: "Events",
                    template: "#= WorkPermitsListView.addEventImg(data)#",
                    width: "5.5%"
                },
                {
                    field: "Description",
                    title: "Work Description",
                    width: "33.5%"
                    //, attributes: { "class": "shortText" } }
                }              
            ]
        });      

       /** var grid = $("#workPermitsGrid").data("kendoGrid");
        var selected = {}; 
                if (options) {
                        workPermitsGrid.setOptions(JSON.parse(options));        
                }
                
                windows.onbeforeunload = function () {
                        localStorage["grid-options"] = kendo.stringify(workPermitsGrid.getOptions());
                        return;
                }
                
                
        
                
                var grid = $("#workPermitsGrid").data("kendoGrid");
        var selected = {};
        var gridOptions = localStorage["kg-options"];
                console.log(gridOptions);
        if (gridOptions) {
            grid.setOptions(JSON.parse(gridOptions));
        }
        else {
            localStorage["kg-options"] = kendo.stringify(grid.getOptions());
        }
                **/
                
        // attaches the tool tip to the cells
        $(".shortText").kendoTooltip({
            content: function (e) {
                var target = e.target; // the element for which the tooltip is shown
                return target.text(); // set the element text as content of the tooltip
            }
        });

        gridDataSource.bind("error", function (error) { if (error.errors != undefined && error.errors.length > 0) { alertBox("Error:" + error.errors[0].error); } else { alertBox("Error fetching data: " + error.status); } });

        $("#advSearchWorkPermitBtn").on("click", function () {
            workPermitsListView.searchWorkPermit($("#omniSearchAdvTxt").val(), $("#omniSearchWorkPermitID").val(), $("#omniSearchContractor").val(), $("#workPermitStatusDropDown").val());
            workPermitsListView.advancedSearchWindow.data("kendoWindow").close();
        });

        $(window).on("omniSearchTriggered", function (event, searchText) { workPermitsListView.searchWorkPermit(searchText, "", "", ""); });

        $(window).on("AdvancedSearchClicked", function (event, searchText) { workPermitsListView.showAdvancedSearch(); });

        if (this.getParameterValue('advsearch') === 'true') {
            this.showAdvancedSearch();
        }
        else if (this.getParameterValue('omnisearch') !== undefined) {
            searchText = this.getParameterValue('omnisearch')
            $("#omniSearchTextBox").val(searchText);
            this.searchWorkPermit(searchText, "", "", "");
        }
        else {
            var grid = $("#workPermitsGrid").data("kendoGrid");
            grid.dataSource.read();
        }
                                
    } 

    WorkPermitsListView.formatPhone = function (phone)
    {
        return phone.replace(/(\d{3})(\d{3})(\d{4})/, '$1-$2-$3');
    }

    /** Redirects the browser to the work permit edit page
    * 
    * @param  sender    object    reference to the kendo grid
    * @returns nothing
    */
    WorkPermitsListView.editWorkPermit = function (e) {
        e.preventDefault();             
        var data = this.dataItem($(e.currentTarget).closest("tr"));
        window.location = 'WorkPermit.aspx?pid=' + data.Id;
    }

    /** Returns a status image
    * 
    * @param  model    object    reference to the work permit model
    * @returns Html with img tag set to the right status image
    */
    WorkPermitsListView.addStatusImg = function (model) {

        if (model.Status === 2) {
            return '<img src="../img/open_wp_status.png" class="statusIcon"/> In Progress';
        }
        else if (model.Status === 3) {
            return '<img src="../img/closed_wp_status.png" class="statusIcon"/> Rejected';
        }
        else if (model.Status === 4) {
            return '<img src="../img/cancelled_wp_status.png" class="statusIcon"/> Cancelled';
        }
        else if (model.Status === 5 ) {
            return '<img src="../img/expired_wp_status.png" class="statusIcon"/> Expired';
        }
        if (model.Status === 6) {
            return '<img src="../img/approved_wp_status.png" class="statusIcon"/> Approved';
        }
    }
        
        /** 
        Get file attachment and display attachement icon
        
        **/
        WorkPermitsListView.addFileImg = function (model) {
        var permitId = model.Id
            return '<a href><img id="permitFile" src="../img/permit-attachment-icon.jpg" class="statusIcon" onclick="WorkPermitsListView.getPermitFile($(this))" ></a>';              
    }

    WorkPermitsListView.getPermitFile = function (e) {
        var grid = $("#workPermitsGrid").data("kendoGrid");

        $(grid.tbody).on("click", "#permitFile", function (e) 
                {
                
            var row = $(this).closest("tr");
            var rowIndex = $("tr", grid.tbody).index(row);
            var id = grid._data[rowIndex].Id;
                $.ajax(
                                {
                    url: PTWApp.getSitePrefix() + '/File/GetWorkPermitFile',
                    type: 'GET',
                    dataType: 'json',
                    data:
                        {
                            workPermitId: id
                        },
                    success: function (data) {
                        var link = document.createElement('a');
                        document.body.appendChild(link);
                        link.href = PTWApp.getSitePrefix() + data.file.Url;
                        link.click();
                    },
                    error: function () {
                        alertBox("Error downloading");
                    }
                });
                        });
        }
        
        
        WorkPermitsListView.onDataBind = function(arg) {
                kgrid = $("#workPermitsGrid").data("kendoGrid");
                localStorage["kendo-grid-options"] = JSON.stringify(kgrid.getOptions());
        }
        

    /** Returns an events checkmark image
    * 
    * @param  model    object    reference to the work permit model
    * @returns Html with img tag set to the right status image
    */
    WorkPermitsListView.addEventImg = function (model)
    {
        if (model.IsEvent === true)
        {
            return '<img src="../img/checkmark.png" class="statusIcon" style=" display: block; margin-left: auto; margin-right: auto; width: 20%"/>'
        }
        else
        {
            return '';
        }
    }
        
            
    
    /** Triggers a work permit search using the parameters as criteria
    * 
    * @param  ominisearch    string    text typed by the user
    *
    * @param  includeContractorActivePermitsOnly    bool    tells the search if the user wants to retrieve only contractors with active permits
    *
    * @param  includeInactiveContractors    bool    tells the search if the user wants to include inactive/deleted contractors in the search
    *
    * @returns nothing
    */
    this.searchWorkPermit = function (omnisearch,workPermitID,contractorName,status)
    {
        if (status === null ||
            status === "")
        {
            status = PTWApp.EnumWorkPermitStatus.Undefined; // default status
        }
                
                console.log("Omnisearch: "+omnisearch + " | contractorID: "+ contractorName + " | WorkPermitID: "+workPermitID + " | Status: "+status);

        var grid = $("#workPermitsGrid").data("kendoGrid");
        grid.dataSource.query({
            page: 1,
            pageSize: 10,
            serverPaging: true,
            serverFiltering: true,
            serverSorting: false,
            filter: {
                "omnisearch": omnisearch,
                "workPermitID": workPermitID,
                                "contractorID": contractorID,
                                "status": status
                
                                
            } 
                        /** logic: "and",
                        filter: [
                                {field: "Id", operator: "eq", value: workPermitID},
                                {field: "ContractorName", operator: "contains", value: contractorName},
                                {field: "Status", operator: "eq", value: status}
                        ] **/
        
                                
        });
        $(".searchContextInfo").text("Search results");
    }

    /** Retrieves a parameter value from the query string (url)
    * 
    * @param  param    string    parameter name to look for
    *
    * @return string   Returns the parameter value if found
    */
    this.getParameterValue = function (param)
    {
        var url = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&');
        for (var i = 0; i < url.length; i++) {
            var urlparam = url[i].split('=');
            if (urlparam[0] == param) {
                return urlparam[1];
            }
        }
    }

    /** Displays the advanced search div
    * 
    * @param  none
    *
    * @return none
    */
    this.showAdvancedSearch = function ()
    {
        this.advancedSearchWindow = $("#advancedSearchDiv");

        this.advancedSearchWindow.kendoWindow(
            {
                width: 370,
                height: 320,
                title: "Advanced Work Permit Search",
                visible: false,
                modal: true,
                actions: ["Close"]
            }
        );

        this.advancedSearchWindow.data("kendoWindow").center().open();
    }

    /** Creates an AJAX request to save the new work permit information
    * 
    * @param  none
    *
    * @return none
    */
    this.createNewWorkPermit = function ()
    {
        window.location = 'WorkPermit.aspx?pid=-1';
    }

Can someone please help me identify what is wrong?



from KendoUI filterable display internal error status:500

No comments:

Post a Comment