0

I am working on SharePoint online 2013. and i add a new Discussion Board App inside my Team site collection. now i name the new app as "News & Announcement", so i was expecting that the defualt link label to create new item will be changed from "new discussion" to "new news & announcements". but unfortunatly this is not the case. so now my App is labeled as "News & Announcements", while its create link is labeled as "new discussion". as follow:-

enter image description here

so now i tried writing the following script to override that label :-

<script>
$( document ).ready(function() {
var interval = setInterval(adjustlabel, 3000);

$('.ms-heroCommandLink span:last').text('New News & Announcments');

function adjustlabel() {
$('.ms-heroCommandLink span:last').text('New News & Announcments');

    }
});
</script>

here is the markup for the link (as shown inside firefox )

enter image description here

side note i provide a timer because user can chose to reload the view (ajax-based request). Now the above script did not work , but when i edit my page i have noted that the link got the new label, but if i save my Page, the label will return back to "new discussion" ! so can anyone adivce on this please? why the script worked only when the page is on edit mode??

1 Answer 1

2

Take a look at render function within sp.ui.discussion.debug.js. You'd find two strings: Strings.STS.L_SPDiscHeroLinkAltText and Strings.STS.L_SPDiscHeroLinkFormat. You can override these string variables and use JSLink's postRender method or use the code below inside a Script Editor.

<script type="text/javascript">
//self-executing anonymous function
(function () {
    // String overrides
    function DiscussionListViewStringOverride() {
        Strings.STS.L_SPDiscHeroLinkAltText = "add new News & Announcements";
        Strings.STS.L_SPDiscHeroLinkFormat = "New News & Announcements";
    }

    DiscussionListViewStringOverride();
    ExecuteOrDelayUntilScriptLoaded(DiscussionListViewStringOverride, "strings.js");
})();
</script>
10
  • thanks for the reply. i added a script editor web part to my page, with the following code <script type="text/javascript" src="https://s*****/Style%20Library/jquery-1.10.2.js"> </script> <script> $( document ).ready(function() { Strings.STS.L_SPDiscHeroLinkAltText = "add new News & Announcments" Strings.STS.L_SPDiscHeroLinkFormat = "New News & Announcments"; }); </script> but it did not change the title, never inside the edit mode nor inside the read mode.. atleast inside my script the title will be change on the edit mode.can u adivce further please?
    – John John
    Nov 14, 2016 at 17:34
  • 1
    Add it without the dom ready. It should work.
    – Aveenav
    Nov 14, 2016 at 17:50
  • ok the later code worked fine, but can you adivce why the first code (with dom ready) did not work ?? second point, now if i do a refresh (ajax based refresh) for the web part which is showing the Discussion board , the label will return back to be "new discussion",, so should i add a timer to re-execute the script each N seconds ??
    – John John
    Nov 15, 2016 at 0:12
  • 1
    see the updated answer. DOM ready didn't work - I think it has do with the sequence of javascript files being loaded particularly strings.js. Better solution would be to apply JSLink prerender and postRender methods but as soon you apply JSLink to this view, things break.
    – Aveenav
    Nov 15, 2016 at 15:27
  • 1
    did you try the updated script for ajax refresh,?
    – Aveenav
    Nov 16, 2016 at 15:19

Your Answer

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

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