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

Get Items from SharePoint List and display in SharePoint using Content Editor Web Part and HTML table

Get Items from SharePoint List and display in SharePoint using Content Editor Web Part and HTML table

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: Refer here to understand more about SPServices.GetListItems.


Step 4: In a Web Part Page, Edit Page and Add Content Editor Web Part.

Step 5: Create a custom List and populate with records.



Step 6: 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 code in Web Part's text editor directly.

<html>
<head>

<SCRIPT type=text/javascript src="http://MySPSite.com/sites/test/DocLib/jquery-1.4.2.min.js"></SCRIPT>
<SCRIPT type=text/javascript src="http://MySPSite.com/sites/test/DocLib/jquery.SPServices-0.7.2.min.js"></SCRIPT>

<title>Contents from MycustomList</title>
</head>

<body>
<table id="myDataTable" border =1 width="95%" align="center">
                        <tr align='left' bgcolor="lightBlue">
                        <td><B>ID</B></td>
                        <td><B>Department</B></td>
                        <td><B>Project</B></td>
                        <td><B>To Do</B></td>
                        <td><B>End Date</B></td>
                        </tr>
 </table>

<SCRIPT type=text/javascript>
          
get() ;

function get()
{                     
            var method = "GetListItems";                 
            var webURL =  $().SPServices.SPGetCurrentSite() ;                     
            var list = "MyCustomList";                      
            var fieldsToRead = "<ViewFields>"+"<FieldRef Name='Name' />" +"</ViewFields>";
            var query = "<Query><OrderBy><FieldRef Name='ID'  Ascending='True' /></OrderBy></Query>";                       
                       
            $().SPServices
            ({
                        operation: method,
                        async: false, 
                        webURL: webURL,
                        listName: list,
                        CAMLViewFields: "<ViewFields Properties='True' />",
                        CAMLQuery: query,                                                                                     
                        completefunc: function (xData, Status)
                         {
                             $(xData.responseXML).SPFilterNode("z:row").each(function() 
                             {
                                  var ID = $(this).attr("ows_ID");
                                  var title = $(this).attr("ows_Title");
                                  var Dept  =  $(this).attr("ows_Department");
                                  var Project =  $(this).attr("ows_Project");
                                  var EndDate = $(this).attr("ows_End_x0020_Date");  

                                  $("#myDataTable").append("<tr align='middle'>" +
                                   "<td align='left'>"+ID+"</td>" +
                                   "<td align='left'>"+ title+"</td>" +
                                   "<td align='left'>"+ Dept+"</td>"  +                                         
                                   "<td align='left'>"+ Project+"</td>" +
                                   "<td align='left'>"+ EndDate+"</td>" + "</tr>");
                               });
                       }
           });
};

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


Step 7: If you need 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.

Get JSON Web Service Data using Content Editor Web Part and Insert that data into SharePoint List.

Get JSON Web Service Data using Content Editor Web Part and Insert that data into SharePoint List.

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 more about JSON Web Service.

Step 3: Refer here to understand about SPServices. This is specialized Jquery to execute SharePoint related operations.

Step 4: In a Web Part Page, Edit Page and Add Content Editor Web Part.

Step 5: 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 code in Web Part's text editor directly.


Step 6: We are trying to accomplish the following here. Using a button "Get JSON Data we will retrieve the JSON data and updata a HTML table. Now another button "Update into SharePoint List" enables you to update the retrieved data into a SharePoint List.

Initially the button to retrieve the JSON data is displayed from the Content Editor Web Part.


When clicked, it retrieves the data and populates a HTML table.Now the button to Update this data into a SharePoint list is also made visible.

When "Update to SharePoint List" is clicked, the first record is displayed. Followed by a message which confirms that this record has been inserted into a SharePoint list.





Alert messages will repeat for all 5 records. Then go to the SharePoint list to confirm if the list has been updated.




The code is as below.

<HEAD>

<TITLE>GetData JSON web service </TITLE>

<script type="text/javascript" src="http://MyJSSite.com/sites/BasicJS/Lib/jquery-1.3.2.min.js"></script>
<script type=text/javascript src="http://MyJSSite.com/sites/BasicJS/Lib/jquery.SPServices-0.5.6.min.js"></SCRIPT>



<SCRIPT type=text/javascript>         
 var JsonData = "http://test.basic.com//%8766987%7D/%7BA561528C?format=daas-JSON";
 function JSONFunction()
 {
  var fullurl = JsonData + '&callback=?';
  alert("The JSON URL IS :: " + fullurl);

   $.getJSON(fullurl,'',function(data)
   {
   //alert("Inside function-data");
   var receivedData = data.entries;
   alert("Length is :: " + receivedData.length.toString());
   for (var i = 0; i < receivedData.length; i++)
   {
    var linktitle = receivedData[i]['LinkTitle'].toString();
    var type  = receivedData[i]['Activity_Type'].toString();
    var edate = receivedData[i]['End_Date'].toString();
    AddRowToTable(i.toString(),linktitle,type,edate);
   }
   document.getElementById('myJsonDataTable').style.visibility = "visible";
   document.getElementById('SpInsertButton').style.visibility = "visible";
  
   });
 }
  
 function AddRowToTable(num,linktitle,type,edate)
 {
     $("#myJsonDataTable").append("<tr align='middle'>" +
    "<td align='left'>"+num+"</td>" +
                                "<td align='left'>"+linktitle+"</td>" +
     "<td align='left'>"+type+"</td>" +
    "<td align='left'>"+edate+"</td>" +     "</tr>");
                               
 }

 function UpdateSharepointFunction()
 {
  var fullurl = JsonData + '&callback=?';
   $.getJSON(fullurl,'',function(data)
   {
   var receivedData = data.entries;
   for (var i = 0; i < receivedData.length; i++)
   {
    var linktitle = receivedData[i]['LinkTitle'].toString();
    var type  = receivedData[i]['Activity_Type'].toString();
    var edate = receivedData[i]['End_Date'].toString();
    CreateNewItem(linktitle,type,edate);
   }

   });
 }

 function CreateNewItem(linktitle,type,edate)
 {
     alert( linktitle + "----" + type + "---- " + edate);
     $().SPServices({
         operation: "UpdateListItems",
         async: false,
         batchCmd: "New",
         listName: "FromWebService",
         valuepairs: [["Title", linktitle], ["PType", type], ["EndDate", edate]],
         completefunc: function(xData, Status) {
         alert("completed");
         }
     });   
 }


</SCRIPT>
</head>

<BODY>

<button onclick="JSONFunction()">Get JSON data</button>

<table id="myJsonDataTable" border =1 width="70%" style="visibility:hidden">
<tr align='left' bgcolor="lightBlue">
 <td><B>Num</B></td>
 <td><B>Title</B></td>
 <td><B>Type</B></td>
 <td><B>End Date</B></td>
</tr>
</table>

<button id="SpInsertButton" onclick="UpdateSharepointFunction()" style="visibility:hidden">Update into SharePoint List</button>

</BODY>
</HTML>
 
Step 7: While inserting into SharePoint custom list, this code again retrieves data from JSON to use the latest data.

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.

Step 9: Refer this post to see the data extracted from GeoPlugin JSON Web Service using a Content Editor Web Part.

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.

List SharePoint Subsites within a Site Collection using Content Editor Web Part and JavaScript

List SharePoint Subsites within a Site Collection 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 "Yes\No" type column.

Step 3: Add Content Editor Web Part.

Step 4: 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 Content Editor Web Part's text editor directly.

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


<title>Sites Within Site Collection</title></head>
<body>
<div id="divId"/> </div>
 

<SCRIPT type=text/javascript>

 var thisSite = $().SPServices.SPGetCurrentSite();
 get() ;

 function get()
 {

  $().SPServices
  ({
     operation: "GetWebCollection",
     webURL:
http://sample.com/sites/mySiteCol
,                              
     completefunc: function (xData, status)
     {

       $(xData.responseXML).find("Web").each(function()
       {
          var webtitle = $(this).attr("Title");
          var weburlvar = $(this).attr("Url");
        
  $("#divId").append("<img     src=http://sample.com/sites/BaisJs/Pics/stsicon.gif>    <a href='"+ weburlvar + "' target='_blank'>" + " " + webtitle + "</a><br/>");
        });
      }
   });
}

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


Step 5: In Content Editor Web Part, within the Web Part Setting, Under Appearance, For Chrome Type select "Title only". Click OK. Click Apply. Publish the Page. Now you can see that this web part shows all Sites within a Site Collection.



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.