Checked null with dateTime in REST API SharePoint

sp13test 281 Reputation points
2021-02-05T12:54:27.367+00:00

I want to get all article pages which Article Date is not null. so I have try to do by this way.

var ArticlePageContentTypeID = "0x010100C568DB52D9D0A14D9B2FDCC96666E9F2007948130EC3DB064584E219954237AF3900242457EFB8B24247815D688C526CD44D";
 var url = "/_api/web/lists/getbytitle('Pages')/items?&$select=ArticleStartDate&$orderby=ArticleStartDate desc&$filter=startswith(ContentTypeId,'" + ArticlePageContentTypeID + "') and ArticleStartDate ne null";
 jQuery.ajax({
   url: url,
   type: "GET",
   headers: { "Accept": "application/json;odata=verbose" },
   success: function(){},
   error: function(){}

  });

but it does not working it. error mention that

"String was not recognized as a valid DateTime."

Please help me if you have idea.

SharePoint Server Development
SharePoint Server Development
SharePoint Server: A family of Microsoft on-premises document management and storage systems.Development: The process of researching, productizing, and refining new or existing technologies.
1,624 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jerryzy 10,571 Reputation points
    2021-02-08T03:13:54.547+00:00

    Hi @sp13test ,

    If you are using SharePoint 2013, then Rest OData didn't support to check null value operation, a workaround is to use CAML Query with a Post Request like this:

    $.ajax({
    type: "POST",
    headers: {
    "accept": "application/json;odata=verbose",
    "content-type": "application/json;odata=verbose",
    "X-RequestDigest": $("#__REQUESTDIGEST").val()
    },
    url: 'http://siteurl/_api/web/Lists/GetByTitle(\'Pages\')/GetItems(query=@v1)?@v1={"ViewXml":"<View><Query><Where><IsNotNull><FieldRef Name=\'ArticleStartDate\' /></IsNotNull></Where></Query></View>"}',
    success: function(data){console.log(data); },
    failure: function(data){console.log(data); }
    });

    SharePoint REST API - CAML Query

    For SharePoint 2016 and Online, currently, it has already supported with null check in endpoint directly.

    Thanks
    Best Regards


    If an Answer is helpful, please click "Accept Answer" and upvote it.
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.