none
Display Latest and only first record(Recently modified) from announcement list using script editor RRS feed

  • Question

  • Hello,

    I have list named as "News" (Type:announcement) which includes columns as : Title, Body.

    I want to display only on record/top news which is latest modified.

    Also just want to show data from "Body" and "Modified" column as below:

    =======================================================

    Latest News

    This is latest news content..

    03-July-2020 13:30

    =======================================================

    Please guide.

    Thanking you in advance.

    Have a nice day.

    Regards,

    Jayashri

    Friday, July 3, 2020 11:48 AM

All replies

  • One simple way is to write a custom webpart, only show the contents you want.

    Here is a walkthrough for your reference, but what you will do is more easier than that.

    https://docs.microsoft.com/en-us/visualstudio/sharepoint/walkthrough-creating-a-web-part-for-sharepoint-by-using-a-designer?view=vs-2019


    Justin Liu Office Apps & Services MVP, MCSE
    Senior Software Engineer
    Learn Microsoft 365 from Microsoft DOCs now!
    Please Vote and Mark as Answer if it helps you.

    Monday, July 6, 2020 1:48 AM
  • Hi,

    Display the Body filed in list view and use CSR to customize the list view.

    Sample demo:

    <style type="text/css">
            .container{
                border-bottom:1px solid;
            }
        </style>
        <script type="text/javascript">
            ExecuteOrDelayUntilScriptLoaded(myCSRListView, 'clienttemplates.js');
            function myCSRListView() {
                var overrideCurrentContext = {};            
                overrideCurrentContext.Templates = {};
                overrideCurrentContext.Templates.Header = "<div>customized list view as card</div>";
                overrideCurrentContext.Templates.Item = ModifiedListViewItem;            
                SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCurrentContext);
            }
    
            function ModifiedListViewItem(ctx) {
                var listItemHtml = '<div class="container">';
                listItemHtml += '<p>' + ctx.CurrentItem.Title + '</p><br /><p>' + ctx.CurrentItem.Body + '</p><br /><p>' + ctx.CurrentItem.Modified + '</div>'
                return listItemHtml;           
            }
        </script>

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Monday, July 6, 2020 2:26 AM
  • Thanks for your reply.

    Just one more question here: If body do not have longer text so can we reduce border line's length according to sizer of text?

    Please guide.

    Thanking you in advance.

    Regards,

    Jayashri

    Monday, July 6, 2020 11:30 AM
  • Hello Guys,

    One easy approach is to compose a custom webpart, displaying just the contents you might like.

    For your guide, here's a walkthrough but what you're going to do is better than that.

    Thanks,

    askmeoffers.com

    Monday, July 6, 2020 12:04 PM
  • Thanks for your reply.

    Actually I am not looking for Custom development.

    Monday, July 6, 2020 12:05 PM
  • Hi,

    You could add dynamic style to the element(s) based on text length.

    Sample demo:

     <style type="text/css">
            .container{
                border-bottom:1px solid;
            }
        </style>
        <script type="text/javascript">
            ExecuteOrDelayUntilScriptLoaded(myCSRListView, 'clienttemplates.js');
            function myCSRListView() {
                var overrideCurrentContext = {};            
                overrideCurrentContext.Templates = {};
                overrideCurrentContext.Templates.Header = "<div>customized list view as card</div>";
                overrideCurrentContext.Templates.Item = ModifiedListViewItem;            
                SPClientTemplates.TemplateManager.RegisterTemplateOverrides(overrideCurrentContext);
            }
    
            function ModifiedListViewItem(ctx) {
                var bodyValue = ctx.CurrentItem.Body;
                //This regex expression use to delete html tags from the Body field
                var regex = /(<([^>]+)>)/ig;
    
                txtbodyValue = bodyValue.replace(regex, "");            
    
                if (txtbodyValue && txtbodyValue.length >= 50) {
                    var listItemHtml = '<div class="container">';
                    listItemHtml += '<p>' + ctx.CurrentItem.Title + '</p><br /><p>' + bodyValue + '</p><br /><p>' + ctx.CurrentItem.Modified + '</div>'
                } else {
                    var listItemHtml = '<div class="container" style="width:50%">';
                    listItemHtml += '<p>' + ctx.CurrentItem.Title + '</p><br /><p>' + bodyValue + '</p><br /><p>' + ctx.CurrentItem.Modified + '</div>'
                }             
                return listItemHtml;           
            }
        </script>

    Best Regards,

    Lee


    Please remember to mark the replies as answers if they helped. If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com.

    SharePoint Server 2019 has been released, you can click here to download it.
    Click here to learn new features. Visit the dedicated forum to share, explore and talk to experts about SharePoint Server 2019.

    Tuesday, July 7, 2020 1:34 AM