Remove Quoted text message from Discussion Board Replies using SPServices\JQuery and Content Editor Web Part.

Remove Quoted text message from Discussion Board Replies using
SPServices\JQuery and Content Editor Web Part.


Step 1: Kindly follow my 
intital post to understand how java script can be used

           in Content Editor Web Part.

Step 2: Refer
here to understand about SPServices. This is specialized Jquery

to execute SharePoint related operations.

Step 3: What is Quoted text and why must it be removed from the replies.

In A Discussion Board, this is the way a particular Discussion topic and its replies are displayed.

If we edit the replies to modify its content, it then does not hide the quoted text anymore. This view is cluttered and undesirable. There are no OOTB ways to fix this issue.
Step 4: So one solution would be to remove the quoted text using scripting
while creating the replies itself.

Step 5: Refer the pics below, when the script is embedded within the page, the reply is created without any text.  




Step 6: Edit the page, Refer intital post to insert a content editor web part.

Step 7: Write the following code in a text. save as html. upload into SharePoint Document Library. Link this html page to content editor web part or write it directly in its text editor.


<html>
<head></head>
<body>
 <SCRIPT type=text/javascript src="http://mysite/sites/test/MyDocs/jquery-1.4.2.min.js"></SCRIPT>
 <SCRIPT type=text/javascript src="
http://mysite/sites/test/MyDocs/jquery.SPServices-0.5.6.min.js"></SCRIPT>
 <SCRIPT type=text/javascript>

 $(document).ready(function()
  {
  var queryStringVals = $().SPServices.SPGetQueryString();
         var ContentTypeId = queryStringVals["ContentTypeId"];
  ///////// *******************************************************
  ////// NEWFORM.ASPX IS USED TO CREATE NEW DISCUSSION QUESTIONS AND
  /////// ALSO ADD REPLIES TO EXISITING DISCUSSIONS\QUESTIONS
  /////// CONTENT TYPE 0X0107 INDICATES WHEN NEWFORM.ASPX IS NOW USED

 ///////TO CREATE REPLIES.
 ////// CLEAR "Body". remove quoted message.
 /////// *******************************************************
  

if (ContentTypeId == '0x0107')
  {
   //alert(ContentTypeId);
   var bodyField = getTagFromIdentifierAndTitle("TextArea","","Body");
   bodyField.value = "";
  }
   });


 function getTagFromIdentifierAndTitle(tagName, identifier, title)
 {
    var len = identifier.length;
    var tags = document.getElementsByTagName(tagName);
    for (var i=0; i < tags.length; i++)
  {
      var tempString = tags[i].id;
      if (tags[i].title == title && (identifier == "" || tempString.indexOf(identifier) == tempString.length - len))
      {     return tags[i];     }
    }
    return null;
 }
 
</SCRIPT>
</Body>
</html
 

Step 8: To remove the identity that the code was generated from Content Editor Web Part, within the Web Part Setting, Under Appearance, For Chrome Type select "None". Click OK. Click Apply. Publish the Page.

Leave your comments below.

No comments: