How to prepare a javasript that shows only the last announcement item

Gulnar 146 Reputation points
2020-09-13T11:02:59.24+00:00

I want to do a javascript that can show only the last announcement in the middle of the main page and If there is no new announcement in the list it should show (no announcements)

Microsoft 365 and Office SharePoint For business Windows
0 comments No comments
{count} votes

Accepted answer
  1. Amos Wu-MSFT 4,051 Reputation points
    2020-09-14T02:27:55.92+00:00

    You could use Ajax to call Rest API to filter the announcement items.

    /_api/web/lists/getbytitle('anno')/items?$filter=Created gt datetime'2020-09-01T00:00:00'  
    

    This Rest API will return all items created after 2020.09.01 00:00,you need to replace it with a js dynamically calculated value.Then you can show the latest item value in page if this Rest API returns values.
    If your main page is a classic page,you could add a script editor in your page add script in it directly.
    If your page is a modern page,you need to create a SPFX to achieve this.SPFX Document


    If the response 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.


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.