Showing posts with label Edit SharePoint NewForm.aspx. Show all posts
Showing posts with label Edit SharePoint NewForm.aspx. Show all posts

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.

Insert javascript code within a SharePoint Page as a Web Part

How to insert javascript code within a SharePoint Page as a Web Part. [Without tools like SharePoint Designer].

Without access to Visual Studio or SharePoint Designer, you can still insert code using Javascript into a SharePoint Page using web Parts like content Editor Web Part or Page Viewer WebPart. 

Step 1: Download js files from this link. SPServices is a very useful jQuery library that has many operations like GetListItems[SPList], GetSite[SPWeb]. You can read about it here. If you need SPServices Js file then download using this link. I used jquery-1.4.2.min.js and jquery.SPServices-0.5.6.min.js for most of my coding references.

Step 2: Upload these files into a Doc libraray in a SharePoint Site\Site Collection.

Step 3: In any SharePoint Site, Create a Web Part Page or use an exisiting one. Edit the Page and Insert a Content Editor Web Part. Refer this blog on how to edit a NewForm.aspx. This content editor web part can be used as text editor to insert Code OR Write code in a txt file, Upload into SharePoint and reference its path to this Content Editor Web PArt.





Illustration Simple Code to get and write the Current Site Url in a Web Part.

<html>
<head>
<SCRIPT type=text/javascript src="/mysites/myDocLibrary/JsFiles/jquery-1.4.2.min.js"></SCRIPT>
<SCRIPT type=text/javascript src="/mysites/myDocLibrary/JsFiles/JsFiles/jquery.SPServices-0.5.6.min.js"></SCRIPT>
<SCRIPT type=text/javascript>
      
            var thisSite = $().SPServices.SPGetCurrentSite();
           //alert(thisSite);
            document.write("The Current Site is " + thisSite);

</SCRIPT>
</head>

<Body>

</Body>
</html>

Step 4 : 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.