0

I am making a fetch to retrieve information from a SharePoint list that meet a certain criteria.

I need the EndDate to be greater than or equal to todays date. I also need to other columns to equal a certain value. HRStatus and SupervisorStatus need to both equal 'Approved'.

Here is the setup for the request:

const compareDate = new Date();

const formatCompareDate = moment(compareDate).format('YYYY-MM-DD');

const empArray = [Array of Names I want to pull];

var filters = empArray.map(function(emp){
    return "EmployeeName/Title eq '" + emp + "'";
});


const leaveRequest = new Request(
    "/_api/web/lists/GetByTitle('Leave Request')/items?$select=EmployeeName/Title,ID,StartDate,EndDate,LeavePurpose,Title,HRStatus,SupervisorStatus&$expand=EmployeeName&$filter=EndDate ge '" + formatCompareDate + "'and HRStatus eq 'Approved' and SupervisorStatus eq 'Approved' and " + filters.join(' or ')
    , {
        method: 'GET',
        credentials: 'include',        
        headers: new Headers({
            "Accept": "application/json; odata=verbose",
        })
    }
);

This is returning all items with the correct cormatCompareDate but it is pulling items that have a null response for either Status Field. I need both of them to be the same value.

1 Answer 1

1

Try using endpoint like this:

"/_api/web/lists/GetByTitle('Leave Request')/items?$select=EmployeeName/Title,ID,StartDate,EndDate,LeavePurpose,Title,HRStatus,SupervisorStatus&$expand=EmployeeName&$filter=EndDate ge '" + formatCompareDate + "'and HRStatus eq 'Approved' and SupervisorStatus eq 'Approved' and (" + filters.join(' or ') + ")"

And you have to use the "internal names" of columns in REST endpoint everywhere (in $select, $expand as well as in $filter).

You can get the internal names of your columns by following this article: How to find the Internal name of columns in SharePoint Online?


Additional Information:

For date column filtering, refer: Filter Created in SP REST API

Your Answer

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

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