Showing posts with label Discussion Board. Show all posts
Showing posts with label Discussion Board. 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.

Query Discussion Board Replies using SPServices\JQuery and Page Viewer Web Part

Query Discussion Board Replies using SPServices\JQuery and Page Viewer 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: In a Web Part Page, Edit Page and Add Page Viewer Web Part.
Step 4: Write the following code in a text. save as html. upload into SharePoint Document Library. Link this html page to page viewer web part.

Step 5: Create a Discussion Board. Add dropdown column called "Reply Priority". This column is hidden in Discussion[Question] content type. In our case, Column "Reply Priority" is visible only to Message[Reply] content.




Step 6: We are trying to accomplish the following here. Display Replies from all questions and load a single table with a chosen Priority Level.





Consider there are 2 questions, Question 1, has one reply with Priority Level = Low, and Question 2 has one reply with Priority Level = Low. Now we need to extract both of these replies and display in a table when Priority Level = Low is chosen.


When Priority Level = Medium or High then delete these rows and load the table with replies with respective Priority Level.

<head>
<SCRIPT type=text/javascript src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></SCRIPT>
<SCRIPT type=text/javascript src="http://sample.com/sites/lib/jquery.SPServices-0.7.2.min.js"></SCRIPT>

<title>Filter Replies </title>
</head>

<body>

<table id="BasicTable" border=0 width="55%" align="left"
style="font-family: Verdana;font-size:8pt" >
<tr>
<td style="width:40%;"><B>Reply type :</B></td>
<td style="width:60%;" colspan="2">
<select id="DropStudies" onchange="getComboA(this)"
style="font-family: Verdana;font-size:8pt">
                                    <option value="Low">Low</option>
                                    <option value="Medium">Medium</option>
                                    <option value="High">High</option>
</select>
</td>
</tr>
</table>          
<br/><br/>

<table id="myDataTable" border=1 width="55%" align="left" style="font-family: Verdana;font-size:8pt;">
<tr align='left' bgcolor="#00579c">
            <td><B>ID</B></td>
            <td style="width:40%;"><FONT COLOR="white">
<B>Main Question</B></td>
            <td style="width:60%;"><FONT COLOR="white">
<b><B>Reply Details</B></td>
</tr>
</table>          

<SCRIPT type=text/javascript>

get() ;  

function getComboA(sel)
{
    var value = sel.options[sel.selectedIndex].value;
    LoadTableFunction();
}

function LoadTableFunction()
{                     
    var table = document.getElementById("myJsonDataTable");                 
    if(table.rows.length >1)
    {
            for(var i = table.rows.length - 1; i > 0; i--)
            {    table.deleteRow(i);}
    }
    get() ;                      
}

function get()
{                     
      var method = "GetListItems";                       
      var webURL =  $().SPServices.SPGetCurrentSite() ;               
      var list = "DBExample";                   
      var fieldsToRead = "<ViewFields>" +"<FieldRef Name='Name' />"
+"</ViewFields>";
                       
      //----------------------------------------------------------------------------
     // GET ALL REPLIES WITH CHOSEN REPLY PRIORITY
     // CONTENT TYPE = MESSAGE RETURNS ONLY REPLIES
     // CONTENT TYPE = DISCUSSION WILL RETURN THE QUESTIONS.
     // THAT IS NOT NEEDED HERE.
     // RESURCIVEALL QUERY OPTIONS
     //------------------------------------------------------------------------------
  
    var query = "<Query><Where><And><Eq><FieldRef Name='ContentType' />
<Value Type='Text'>Message</Value></Eq>";               
    query = query +"<Eq><FieldRef Name='Reply_x0020_Priority' />
                        <Value Type='Choice'>" + DropStudies.value +
"</Value></Eq></And></Where>";
     query = query + "<OrderBy><FieldRef Name='ID' Ascending='True' />
  </OrderBy></Query>";
                                               
     var qOptions = "<QueryOptions><ViewAttributes Scope='RecursiveAll'/>
</QueryOptions>";
                                               
     GetData(method,list,webURL,fieldsToRead,query,qOptions,list);            
};
           

function GetData(method,list,webURL,fieldsToRead,query,qOptions,Folder)
{                     
$().SPServices
({
    operation: method,
    async: false, 
    webURL: webURL,
    listName: list,
    CAMLViewFields: "<ViewFields Properties='True' />",
    CAMLQuery: query,
    CAMLQueryOptions: qOptions,                                           
    completefunc: function (xData, Status)
    {
       $(xData.responseXML).SPFilterNode("z:row").each(function() 
       {
       // GET ID OF THE REPLY                                                     
      //--------------------------------------------
      var ID = $(this).attr("ows_ID");                                                                                                                               
                                                                       
      // QUESTION IS  n[5].toString()
     // LINK TO THE QUESTION IS IN var mainQuestion
    //-----------------------------------------------------------
    var fileDirRef  =  $(this).attr("ows_FileDirRef");
    var n= fileDirRef.split("/");
    var mainQuestion = "http://sample.com/sites/" + n[1].toString() + "/" +
 n[2].toString() +"/"+ n[3].toString()  +
"/"+ n[4].toString() + "/"+ n[5].toString();
    mainQuestion = mainQuestion.replace(/[" "]/g, "%20");
                                                           
   // REMOVE THE REPLY FROM THE OTHER DETAILS IN BODY
   //----------------------------------------------------------------------
    var QuestionDetail = $(this).attr("ows_Body");                                                
    var q = QuestionDetail.split("From");
    var q1 = q[0].toString();
  // REMOVE THE HORIZONTAL LINE
  //-----------------------------------------------
    var q2 = q1.split("<hr class=ms-disc-quotedtext>");                                        
                                   
// REPLY IS  q2[0].toString()
// LINK TO THE QUESTION IS IN var directLink
//--------------------------------------------
var directLink = "http:/sample.com/sites/" + n[1].toString() + "/" +
 n[2].toString() +"/"+ n[3].toString()  +
"/"+ n[4].toString() + "/DispForm.aspx?ID=" +  ID.toString();
directLink = directLink.replace(/[" "]/g, "%20") + "&Source=" + mainQuestion;
var reply = q2[0].toString() + "<a href='" + directLink + "'target=_blank>Link to Reply</a>";                                            
                                                                                                                       
$("#myDataTable").append("<tr align='left'>" +
            "<td align='left' valign='top'>"+ID+"</td>" +
             "<td align='left' valign='top'>
<a href='" + mainQuestion + "'target=_blank>"
+ n[5].toString() +"</a></td>" +                                                                      
            "<td align='left' valign='top'>"+reply+"</td>" +                                                              
            "</tr>");          
      });
  }
  });
}

</script>
</body>
</html>
 


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

Step 8: Refer this post to get Items from SharePoint List and display in SharePoint using Content Editor Web Part and HTML table
.

Leave your comments below.

NewForm.aspx filter Column based on another column -Cascade Drop Down using Content Editor Web Part and JavaScript.[Like category - sub category]

Modify NewForm.aspx to filter one SharePoint Column based on another column -Cascade Drop Down using Content Editor Web Part and JavaScript.[Like category - sub category/State - City]


Step 1: Kindly follow my intital post to understand how java script can be used in Content Editor Web Part.

Step 2: Here we will be using State -City relationship. City will be filtered based on State.

Step 3: Create 3 lists.

List called "State" : Custom list with a column "Title" with all states.



List called "CityState" : Custom list with a column 'City' and one for its State. State Column will be lookup to the previous list "State". Here I have renamed "Title" column as "City".





 City will hold column "City" information. State will be a dropdown that loads as a lookup.


List called "Data" : Custom list with a column to have Company name, a column for State[ lookup to the column "Title" in first list "State"], a column for city[ lookup to "City" column of second list "CityState"]


Now State is a lookup column and brings all the value from the first list "State".

Now City is a lookup column and brings all the value from the column "City" in the list "CityState" . So far no filtering is happening.



Step 3: Edit the page. You can modify the URL to edit NewForm.aspx. To the end of the URL append PageView=Shared&ToolPaneView=2. This will open the form in edit mode.

your URL must be like this http://sample.com/sites/MySPSite/Lists/Data/NewForm.aspx?PageView=Shared&ToolPaneView=2

Step 4: Add Content Editor Web Part.



Step 5: Write the following code in a text. save as html. upload into SharePoint.Link this html page to content editor web part or Write code in Web Part's text editor directly. SPSErvices JS File  helps us with the SPCascadeDropDown function.

<SCRIPT type=text/javascript src="http://mysite.com/sites/MySite/Documents/jquery-1.4.2.min.js"></SCRIPT>
<SCRIPT type=text/javascript src="http://mysite.com/sites/MySite/Documents/jquery.SPServices-0.5.6.min.js"></SCRIPT>
<SCRIPT type=text/javascript>

$(document).ready(function(){

        $().SPServices.SPCascadeDropdowns({
        relationshipList:"CityState",
        relationshipListParentColumn:"State",
        relationshipListChildColumn:"Title",
        parentColumn:"State",
        childColumn:"City"
      });
  
});


</SCRIPT>

Step 6: After the content editor web part is saved and you exit the page from edit mode, City gets filtered based on the State.




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

Step 8: Now instead of showing all cities depending upon the selected state, you need to show only a particular set of cities based on a CAML query, then that also can be achieved.

Step 9: Create a column of type "Yes\No" in second list "CityData" called "Visible".





Step 10: Now add the CAML query to the SPServices.SPCascadeDropDown function. Notice the comma after the ChildColumn.

 $(document).ready(function(){

        $().SPServices.SPCascadeDropdowns({
        relationshipList:"CityState",
        relationshipListParentColumn:"State",
        relationshipListChildColumn:"Title",
        parentColumn:"State",
        childColumn:"City",
        CAMLQuery: "<Eq><FieldRef Name='Visible' /><Value Type='Boolean'>1</Value></Eq>"
      
      });
  
});

Step 11:  Now for a selected State, Its relevant Cities with Visible ="True" only gets displayed.



Leave your comments below.

Pre populate SharePoint DropDown column in NewForm.aspx depending on query String using Content Editor Web Part and JavaScript


Pre populate SharePoint DropDown column in NewForm.aspx depending on query String  using Content Editor Web Part and JavaScript.


Step 1: Kindly follow my intital post to understand how java script can be used in Content Editor Web Part.

Step 2: Consider a list like "Announcement"  with custom "Drop Down" type column.



Step 3: Edit the page. You can modify the URL to edit NewForm.aspx. To the end of the URL append PageView=Shared&ToolPaneView=2. This will open the form in edit mode.

your URL must be like this http://sample.com/sites/BasicJs/Lists/Announcements/NewForm.aspx?PageView=Shared&ToolPaneView=2

Step 4: Add Content Editor Web Part.

Step 5: Write the following code in a text. save as html. upload into SharePoint.Link this html page to content editor web part or Write code in Web Part's text editor directly.



Step 6: Code. Here the query string value from the URL will determine with what value column "Announcement Category" must be populated with.If the URL is like http://sample.com/sites/BasicJs/Lists/Announcements/NewForm.aspx?AnnouncementCategory=Public

<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>


$(document).ready(function()
 {

var queryStringVals = $().SPServices.SPGetQueryString();
        var AnnCategory = queryStringVals["AnnouncementCategory"];
var AnnCategorytField = getTagFromIdentifierAndTitle("select","","Announcement Category");
//alert("Control is " + AnnCategorytField.name);  
setSelectedOption(AnnCategorytField,AnnCategory); 
  });

function setSelectedOption(select, value)
{
var opts = select.options;
var l = opts.length;
if (select == null) return;
for (var i=0; i < l; i++) 
{
if (opts[i].text == value) 
{     
     select.selectedIndex = i;
     return true;
    }
 }
return false;
}

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>
</head> 
<Body></Body>
</html>

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

Step 8: Now you can see that the column "Announcement" is populated with the value from the query string "Public".


Leave your comments below.

Pre populate SharePoint Drop Down column in NewForm.aspx using Content Editor Web Part and JavaScript.


Pre populate SharePoint Drop Down column in NewForm.aspx using Content Editor Web Part and JavaScript.


Step 1: Kindly follow my intital post to understand how java script can be used in Content Editor Web Part.

Step 2: Consider a list like "Announcement"  with custom "Drop Down" type column.



Step 3: Edit the page. You can modify the URL to edit NewForm.aspx. To the end of the URL append PageView=Shared&ToolPaneView=2. This will open the form in edit mode.

your URL must be like this http://sample.com/sites/BasicJs/Lists/Announcements/NewForm.aspx?PageView=Shared&ToolPaneView=2

Step 4: Add Content Editor Web Part.

Step 5: Write the following code in a text. save as html. upload into SharePoint.Link this html page to content editor web part or Write code in Web Part's text editor directly.



Step 6: Code. Here we try to set the drop down to a predefined value "Public".


<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>


$(document).ready(function()
 {
var AnnCategorytField = getTagFromIdentifierAndTitle("select","","Announcement Category");
//alert("Control is " + AnnCategorytField.name);  
setSelectedOption(AnnCategorytField,"Public"); 
  });

function setSelectedOption(select, value)
{
var opts = select.options;
var l = opts.length;
if (select == null) return;
for (var i=0; i < l; i++) 
{
if (opts[i].text == value) 
{     
     select.selectedIndex = i;
     return true;
    }
 }
return false;
}

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>
</head> 
<Body></Body>
</html>


Step 7: 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. Now you can see that the column "Announcement Category" shows Public.


Step 8: Check my next post to populate this "Drop Down" column depending upon the value from the Query string.
Leave your comments below.