0

I am working with SharePoint 2010 lists and I am trying to populate the list data in a page using a text box and button where in text box I enter the name of the person and click on button which gives me the content related to that person from the list. The list has three columns Employee Name(name of the person), created date, Title. I am getting the data but my problem here is every time I have to enter the entire name irrespective of caps and small letters as well. For e.g if the person name is "Vikram, Seth" or vikramseth@gmail.com, i have to enter as it is. But I am looking for something even i enter lowercase like "vikram, seth" or vikram it should pull that person related data. I am showing the results in jquery datatable. please find the code I tried. `

function Init() {

    _clientContext = new SP.ClientContext.get_current();
    _web = _clientContext.get_web();

    $("#btnGetResults").click(function () {
        EmployeeDataSub = [];
         Name = $('#txtEmp').val();
         DisDep = $('#txtDisDep').val();
         fromDate = $('#EmployeefrmDate').val();
         GetReports(Name, fromDate);

    });
}

$(document).ready(function () {

    $(document).ready(function () { ExecuteOrDelayUntilScriptLoaded(Init, "sp.js"); });

});

function GetReports(empName, fromDate, EmployeeBy) {
    var listEmployee = _web.get_lists().getByTitle("Shout outs");
    var camlQuery = new SP.CamlQuery();
   // camlQuery.set_viewXml('<View><Query><Where><And><Eq><FieldRef Name="ShoutOutTo" /><Value Type="User">' + empName + '</Value></Eq><Eq><FieldRef Name="Created" /><Value IncludeTimeValue="FALSE" Type="DateTime">' + fromDate + '</Value></Eq></And></Where><OrderBy><FieldRef Name="Modified" Ascending="True" /></OrderBy></Query></View>');
   // camlQuery.set_viewXml('<View><Query><Where><Neq><FieldRef Name="ID" /><Value Type="Number">0</Value></Neq></Where><OrderBy><FieldRef Name="Title"/></OrderBy></Query></View>');
   camlQuery.set_viewXml('<View><Query><Where><And><Neq><FieldRef Name="ID" /><Value Type="Number">0</Value></Neq><Eq><FieldRef Name="_ModerationStatus" /><Value Type="ModStat">0</Value></Eq></And></Where><OrderBy><FieldRef Name="_ModerationStatus" Ascending="True" /></OrderBy></Query></View>');
    //camlQuery.set_viewXml('<View><Query><Where><Eq><FieldRef Name="_ModerationStatus" /><Value Type="ModStat">0</Value></Eq></And></Where><OrderBy><FieldRef Name="_ModerationStatus" Ascending="True" /></OrderBy></Query></View>');
    //camlQuery.set_viewXml('<View><Query><Where><And><And><Neq><FieldRef Name="ID" /><Value Type="Number">0</Value></Neq><Eq><FieldRef Name="_ModerationStatus" /><Value Type="ModStat">0</Value></Eq><FieldRef Name="Author", LookupId="TRUE" /><Value Type="Integer">' + EmployeeBy +'</Value></And></And></Where><OrderBy><FieldRef Name="_ModerationStatus" Ascending="True" /></OrderBy></Query></View>');
    this.EmployeeListItemCol = listEmployee.getItems(camlQuery);
    _clientContext.load(EmployeeListItemCol);
    _clientContext.executeQueryAsync(Function.createDelegate(this, this.onGetReportsSuccess), Function.createDelegate(this, this.onGetReportsFailed));

}

function onGetReportsSuccess() {

    try {
        var empName;
        //var appstatus = "";
        //var mod;
        var enumerator = EmployeeListItemCol.getEnumerator();
        while (enumerator.moveNext()) {
            var listItem = enumerator.get_current();
            empName = listItem.get_item("ShoutOutTo").get_lookupValue();
            //var action = listItem.get_item("_ModerationStatus");
            var Title = listItem.get_item("Title");
            var createdOn = listItem.get_item("Created");
            var distDeput = listItem.get_item("DistrictDeputate");
            //action = "_ModStat";
            var appStatus = ["Approved", "Denied", "Pending", "Draft", "Scheduled"];
            var modStatAsNumber = 0;
            var modStatAsText = appStatus[modStatAsNumber];
            var EmployeeBy = listItem.get_item("Author").get_lookupValue();
            var anony = ["Anonymous", "No"];
            var anonynumb = 0;
            var anonyasText = anony[anonynumb];
            var anonymous = listItem.get_item("AnonymousCheck");
            //if (anonymous === 1) {
            //EmployeeBy = "Anonymous";
            //}
            //set approval status to Approved (0)
            //ListItem.set_item('_ModerationStatus', 0);



            if (empName === Name && distDeput != DisDep) {
                var newItem = {};
                newItem["Employee"] = empName;
                if (anonymous == 1) {
                    newItem["Author"] = anonyasText;
                }
                else {
                    newItem["Author"] = EmployeeBy;
                }
                newItem["Title"] = "<a href='https://examplesite.com/sites/RECOGNITION/Employee/Pages/Employeedetail.aspx?itmId=" + listItem.get_id() + "'>" + Title + "</a>";
                //newItem["Title"] = Title;
                newItem["CreatedOn"] = createdOn;
                newItem["District/Deputate"] = distDeput;
                //newItem["_ModerationStatus"] = modStatAsText;
                EmployeeDataSub.push(newItem);
            }
            else {
                if (distDeput === DisDep) {
                    var newItem = {};
                    newItem["Employee"] = empName;
                    if (anonymous == 1) {
                        newItem["Author"] = anonyasText;
                    }
                    else {
                        newItem["Author"] = EmployeeBy;
                    }
                    newItem["Title"] = "<a href='https://examplesite.com/sites/RECOGNITION/Employee/Pages/Employeedetail.aspx?itmId=" + listItem.get_id() + "'>" + Title + "</a>";
                    //newItem["Title"] = Title;
                    newItem["CreatedOn"] = createdOn;
                    newItem["District/Deputate"] = distDeput;
                    //newItem["_ModerationStatus"] = modStatAsText;
                    EmployeeDataSub.push(newItem);
                }

            }
        }
        $("#tblEmployeeReport").empty();
        var shootOut = $("#tblEmployeeReport").DataTable({
            "aaData": EmployeeDataSub,
            "bLengthChange": false,
            "bPaginate": false,
            "oLanguage": {
                "sEmptyTable": "No Items to show",
                "sInfoEmpty": ""
            },
            "sDom": '<"top">f<"bottom"><"clear">',
            "aoColumns":  [{ "sTitle": "Title", "mData": "Title", "sWidth": "10%", "render": function (data, type, row, meta) {
                            return '<a onclick="alert(' + data + ');" href="#">' + data + '</a>';
                        }
                        },  
                          { "sTitle": "District/Deputy", "mData": "District/Deputate", "sWidth": "10%" },           
                          { "sTitle": "Shootout To", "mData": "Employee", "sWidth": "10%" },
                          { "sTitle": "Employee By", "mData": "Author", "sWidth": "10%" },
                        { "sTitle": "Employee Date", "mData": "CreatedOn", "sWidth": "8%" }
                        ],
            "bJQueryUI": true,
            "bSort": true,
            "bAutoWidth": true,
            "iDisplayLength": 100,
            "sPaginationType": "full_numbers",
            "bStateSave": true,
            "bDestroy": true
        });

    }
    catch (err) {
        alert(err);
    }
}

function onGetReportsFailed(sender, args) {
    alert("Failed to load results..");

}

`

0

I found the solution after lots of tries...to get the result use JavaScript "string contains" where you have to use "IndexOf" I just had to change my condition in if statement to if (empName.toUpperCase().indexOf(Name.toUpperCase()) > -1 && distDeput != DisDep) {

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.