Understanding REST in SharePoint in 2010 and 2013

One very important technology interface that is widely used in SharePoint is called REST,

or Representational State Transfer. By providing access to SharePoint lists and libraries, a developer can find many useful ways to make pages more dynamic.

First, the REST interface in SharePoint gathers data from lists and items by using HTTP resources that can be accessed by using remote URLs.

Remember the GET and POST verbs? Well now a few more verbs have been added so operations in SharePoint REST interface include CREATE, READ, UPDATE, DELETE (C.R.U.D.). Client-server layers are tighter so other applications from different platforms can easily connect to SharePoint list and libraries. REST also offers developers integrations with ADO.NET Data Services.

Using a specific URL (see below), a developer can query data in browser window and display information from the SharePoint Foundation as XML. REST supports JavaScript Object Notation (JSON). So using REST queries, a developer can retrieve list data in XML format.

http://myserver/_vti_bin/ListData.svc

Advertisements

How to fix Open Site bug in SharePoint Designer 2013

Installed a fresh version of SharePoint Designer 2013 on my desktop and when I tried opening a new site, it would crash.

Prior to installing SP2013 Designer, I had to de install a beta version. Apparently, the de install does not clean up registry

GUID values.

HOW TO FIX

HOW TO FIX

Go to Start > Search all program and files and type in ‘Regedit’

Navigate you way down the tree until you get to Open site for SharePoint 2010 (14 HIVE)

SharePoint Designer 2010 (14.0)

HKEY_CURRENT_USERSoftwareMicrosoftOffice14.0CommonOpen FindMicrosoft SharePoint DesignerSettingsOpen Site

Then navigate you way down to Open Site for SharePoint 2013 (15 HIVE)

SharePoint Designer 2013 (15.0)

HKEY_CURRENT_USERSoftwareMicrosoftOffice15.0CommonOpen FindMicrosoft SharePoint DesignerSettingsOpen Site

Compare your Client GUID values and make note if they are the same value. If so, Delete both of the ClientGUID keys. Highlight the key,

Right click and delete. After you delete each of these keys, you should be able to open site in both versions of SharePoint Designer.

Get the GUID value of a SharePoint List and item ID using Javascript

I coded some Javascript that will retrieve the GUID value of a SharePoint list and the first item ID of that list.

Once all the values have been determined, Javascript will open the Infopath form of that list using the

SharePoint Client Side Dialog object.



<script type="text/javascript">


 function OpenDialogOki() {
      
       var options = SP.UI.$create_DialogOptions();
       options.resizable = 1;
       options.scroll = 1;
       
       	 clientContext = new SP.ClientContext.get_current();					
		spWebobj = this.clientContext.get_web();
		spListobj = spWebobj.get_lists().getByTitle("MessagefromOki");
		var spCamlQuery = new SP.CamlQuery();
		var spViewXML = '<View><Query /></View>';
		spCamlQuery.set_viewXml(spViewXML);
		spListobjItems = spListobj.getItems(spCamlQuery);
	
			
		clientContext.load(spWebobj);
		clientContext.load(spListobjItems);  
        this.collList = spWebobj.get_lists();
	    clientContext.load(collList, 'Include(Title, Id)');
        
        // get the GUID info
        var listInfo = '';
		var listEnumerator = collList.getEnumerator();
			   while (listEnumerator.moveNext()) {
			      	var oList = listEnumerator.get_current();
			         
			        if ( oList.get_title() == "MessageFromOki") {
			             listInfo += 'Title: ' + oList.get_title() + ' ID: ' + oList.get_id().toString() + '\n';
			             var oki_guid = oList.get_id().toString();
			              }	
			           }
			    
         //window.OkiItemID - global variable of the list item ID        		
          options.url =  "/Lists/MessageFromOki/Item/displayifs.aspx?List=" + oki_guid + "&ID=" + window.OkiItemID;
          SP.UI.ModalDialog.showModalDialog(options);
   } 
   

 
 function OpenDialogSal() {
      
       var options = SP.UI.$create_DialogOptions();
       options.resizable = 1;
       options.scroll = 1;
       
       	clientContext = new SP.ClientContext.get_current();					
		spWebobj = this.clientContext.get_web();
		spListobj = spWebobj.get_lists().getByTitle("MessagefromSal");
		var spCamlQuery = new SP.CamlQuery();
		var spViewXML = '<View><Query /></View>';
		spCamlQuery.set_viewXml(spViewXML);
		spListobjItems = spListobj.getItems(spCamlQuery);
	
			
		clientContext.load(spWebobj);
		clientContext.load(spListobjItems);  
        this.collList = spWebobj.get_lists();
	    clientContext.load(collList, 'Include(Title, Id)');
        
        // get the GUID info
        var listInfo = '';
		var listEnumerator = collList.getEnumerator();
			   while (listEnumerator.moveNext()) {
			      	var oList = listEnumerator.get_current();
			         
			        if ( oList.get_title() == "MessageFromSal") {
			             listInfo += 'Title: ' + oList.get_title() + ' ID: ' + oList.get_id().toString() + '\n';
			             var sal_guid = oList.get_id().toString();
			              }	
			           }
	      options.url =  "/_layouts/listform.aspx?PageType=4&ListId=" + sal_guid + "&ID=" + window.SalItemID;
     
         SP.UI.ModalDialog.showModalDialog(options);
   } 
  




			    var tpj = jQuery;
			    tpj.noConflict();
                 
			    tpj(document).ready(function () {
 			
              if (typeof(_spBodyOnLoadWrapper) != 'undefined') {
                   _spBodyOnLoadWrapper();
              }
              
              
              
			  if (tpj.fn.cssOriginal != undefined)
			            tpj.fn.css = tpj.fn.cssOriginal;
			       		tpj('#services-example-1').services(
						{
						    width: 920,
						    height: 300,
						    slideAmount: 5,
						    slideSpacing: 30,
						    carousel: "off",
						    touchenabled: "on",
						    mouseWheel: "on",
						    hoverAlpha: "off", 		     // Turns Alpha Fade on/off by Hovering
						    slideshow: 0, 			    // 0 = No SlideShow, 1000 = 1 sec Slideshow (rotating automatically)
						    hovereffect: "on", 		    // All Hovereffect on/off
						    callBack: function () { } 	//Callback any Function after loaded
						  
						});
					 });
			    
			    
			   			    
			    
			    		      
		      ExecuteOrDelayUntilScriptLoaded(getOkiTitle, "sp.js");
					
                 function getOkiTitle() {
                   
			  	    clientContext = new SP.ClientContext.get_current();					
					spWebobj = this.clientContext.get_web();
					spListobj = spWebobj.get_lists().getByTitle("MessagefromOki");
					var spCamlQuery = new SP.CamlQuery();
					var spViewXML = '<View><Query /></View>';
					spCamlQuery.set_viewXml(spViewXML);
					spListobjItems = spListobj.getItems(spCamlQuery);
					clientContext.load(spWebobj);
					clientContext.load(spListobjItems);                     
                 						
					// need to retrieve GUID for List MessageFromSal, MessageFromOki
			    	 this.collList = spWebobj.get_lists();
			    	 clientContext.load(collList, 'Include(Title, Id)');
					 clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));
		
					
				}
				
				
								
			 function onQuerySucceeded() {
                clientContext.executeQueryAsync(onSuccess, onFail);
               }
			
			 function onQueryFailed(sender, args) {
			    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
			 }

	
			function GetSalTitle() {
					clientContext = new SP.ClientContext.get_current();
					spWebobj = this.clientContext.get_web();
					spListobj = spWebobj.get_lists().getByTitle("MessagefromSal");				
					var spCamlQuery = new SP.CamlQuery();
					var spViewXML = '<View><Query /></View>';
					spCamlQuery.set_viewXml(spViewXML);
					spListobjItems = spListobj.getItems(spCamlQuery);
					clientContext.load(spWebobj);
					clientContext.load(spListobjItems);
					clientContext.executeQueryAsync(onSuccess2, onFail);
				}
					
					
			function onSuccess2() {
					
					  	liCount = spListobjItems.get_count();
					  	//alert (liCount);
					    for (x = 0; x < liCount; x++) {
					        var listItem = spListobjItems.itemAt(x);
					        var itemTitle  = listItem.get_item('Title');
					      	var SalItemID  = listItem.get_id();
					     	//window.SalItemID = SalItemID;  
							//display dynamic title on the page
					        document.getElementById("SaloTitle").innerHTML = itemTitle;		      					                     
					    }
					       window.SalItemID = SalItemID; 
					     	
                       }
	
					
				
				function onSuccess() {
					// get the GUID value of MessageFromOki list
					    liCount = spListobjItems.get_count();
					    for (x = 0; x < liCount; x++) {
					        var listItem = spListobjItems.itemAt(x);
					        var itemTitle  = listItem.get_item('Title');
					        var OkiItemID  = listItem.get_id();
					        //display dynamic title on the page
					    	document.getElementById("OkiTitle").innerHTML = itemTitle;
					        				          
					     }
					    // global variable of the list item to display
					     window.OkiItemID = OkiItemID;  
                         GetSalTitle()
                        }
	
					function onFail() {
					    alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());   
					}
					

				
			
			</script>




How to fix the security issue with content deployment wizard

Customizing SharePoint 2010 Blog Posts

In this article I will explain how it’s possible to make style customizations to SharePoint blogs. When a blog site is created, SharePoint builds a list called Post. This list contains all the articles published to the blog. The goal to this customization is to add another column to the list called ‘Written by’ and use a column type of Person or Group. The reason for this column is to display the author’s name of the post instead of showing the ‘Created By’ column. Created by displays the name of the person who published the post. Written by column by will display a choosen name instead.

blog

Blogs are customized in SharePoint using XSLT. Remember that XSLT is a style transformer for XML data. Merging XSLT with XML data will output a results page, in our case, the blog postings.

To Begin Customization
A default.aspx page is also created as the home page for the blog. Before you make any changes in Designer, its a good idea to make a backup copy of the .aspx files you plan on editing. You know its very easy to break SharePoint so be careful and protect yourself with backups!

Open default.aspx in Designer and in the Design view click on the XSltListViewWebPart so it is highlighted. When the ribbon changes to ListViewTools, select the Design tab.

design

Click on the Customize XSLT dropdown and the select ‘Customize the entire view’. This action pulls the XSL from the blog.xsl into the page so it can be viewed and customized.
Blog.xsl is an XSLT file that resides in the _layouts folder on the front end web server.
The object here is to view the .xsl file that is being used and to customize that file.

Look for the line of code:

<xsl:include href="/_layouts/xsl/blog.xsl"/> 

Move your curosr over the code and press control key to see cursor change. Control-Click on the code and a blog.xsl will open as a new page in Designer. Save a copy of blog.xsl and put it in a directory such as ‘XSL’ in the root site of the Site Collection. Give it a different name.

Close default.aspx without saving changes. Open it again and the look for the tag. Add the Written by tag as shown below:

<ViewFields>
<FieldRef Name="Title"/>
<FieldRef Name="Body"/>
<FieldRef Name="Author"/>
<FieldRef Name="PostedByWithDate"/>
<FieldRef Name="CategoryWithLink"/>
<FieldRef Name="Permalink"/>
<FieldRef Name="EmailPostLink"/>
<FieldRef Name="NumCommentsWithLink"/>
<FieldRef Name="PublishedDate"/>
<FieldRef Name="PostCategory"/>
<FieldRef Name="Written_x0020_By"/>
</ViewFields>

Save the file. Go to your saved blog.xsl file and go to the following section:


<xsl:when test="@Name='Author'"><span class="ms-postfootercolor"><xsl:value-of select="'by '"/></span><xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes">&amp;nbsp;</xsl:text><xsl:value-of select="$thisNode/@Author.span" disable-output-escaping="yes" /></xsl:when>

and replace the code with this:


<!-- For the author field, render it using the span style and preceed it with the word "by"--> 
<xsl:when test="@Name='Author'">
<xsl:variable name="ShowPerson">
<xsl:choose>
<xsl:when test="string-length($thisNode/@Written_x0020_By.id) &gt; 0">
<xsl:value-of select="$thisNode/@Written_x0020_By.span" disable-output-escaping="yes"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$thisNode/@Author.span" disable-output-escaping="yes" />
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<span class="ms-postfootercolor" ><xsl:value-of select="'by '"/></span>
<xsl:text disable-output-escaping="yes" ddwrt:nbsp-preserve="yes" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime">&amp;nbsp;</xsl:text>

<span class="ms-postfootercolor" style="background-color:yellow; font-weight:bold"> <xsl:value-of select="$ShowPerson" disable-output-escaping="yes" /></span>
</xsl:when>

The last step you need to do is link the new xslt stylesheet to the webpart. In the browser, open the Tool Pane for the ListView web part and expand Miscellaneous.
In the XSL field, add the path name to your newly created XSLT file that you saved in XSL document library. Save your changes.

mis

Now when you view the Post page in the browser you should see the name of the person you choose in the Written by column in yellow. Feel free to change yellow to transparent or you can remove the style altogether.

yellow

Thanks to Marc Anderson for his XSLT code.

Retrieving a List Title Using Javascript

Recently had a project where I needed display the title of a SharePoint list inside an html file.

This can be accomplished by working with SharePoint’s Client Object Model using some Javascript.

In this example I use JavaScript to retrieve the title from the SharePoint list called ‘MySharePointList.’

Start first by creating an empty div inside the body tag and give it an id value.

<div id="MyListTitle" > </div>

Next use the javascript below:

<script type="text/javascript"> 
ExecuteOrDelayUntilScriptLoaded(

function GetListTitle() {

clientContext = new SP.ClientContext.get_current();

spWebobj = this.clientContext.get_web();

spListobj&nbsp;= spWebobj.get_lists().getByTitle("MySharePointList");

var spCamlQuery = new SP.CamlQuery();

var spViewXML = '';

spCamlQuery.set_viewXml(spViewXML);

spListobjItems = spListobj.getItems(spCamlQuery);

clientContext.load(spWebobj);

clientContext.load(spListobjItems);

clientContext.executeQueryAsync(onSuccess, onFail);

}, "sp.js");

function onSuccess() {

liCount = spListobjItems.get_count();

for (x = 0; x &lt; liCount; x++) {

var listItem = spListobjItems.itemAt(x);

var itemTitle&nbsp; = listItem.get_item('Title');

document.getElementById("MyListTitle").innerHTML&nbsp;= itemTitle;

}

}

function onFail() {

alert('request failed ' + args.get_message() + '\n' + args.get_stackTrace());

}

</script> 

InfoPath 2010 : How to get the user’s name to appear in the form

Infopath 2010 : How to get a user’s name or account to appear in the form

If you need to create an InfoPath form with the user’s name or account appear in a form, InfoPath has a way to connect to SharePoint’s UserProfile service. This article will explain the process to set up a proper data connection in the InfoPath form and then display user names, accounts, emails etc.

If you want to return the Account ID value back to the form, InfoPath has a build-in functions to help retrieve that.

Add a field to you form, right click Textbox properties, go to Data tab, then click the Insert formula button in

You can select the username function to return the name of the person filling out the form.
This will likely return first initial and last name.

By adding a concatenation formula to the username you can modify it so it appears as an email.

Test the different functions in order to achieve your desired results.

Creating the Data Connection

The other way to get user’s information is through the UserProfile Services built in SharePoint.

In your InfoPath form, select the Data tab and then click ‘Data Connections’ button.

In the Data Connections dialog window click ‘Add’ which displays the Data Connection wizard.

Be sure the radio button ‘Receive data’ is selected and then click Next. Now the option to choose
is “Soap Web Service.” You need to specify the User Profile Service URL. The format of the URL is
something like:

http://yourwebserver/mysite/mysite2/_vti_bin/UserProfileService.asmx ?WSDL

Note: Be sure to call the User Profile Service from the same location as your Infopath form. So if your form
is located under mysite2, the make sure the URL points to that site.

Click next until you see the window below and then choose “GetUserProfileByName”

Click next till you get to the last window. Leave the checkbox selected for “Automatically retrieve data

when the form is open.” This way, the field will automatically load users name every time the form is
opened in a browser window. You should now have two data connections set up.

Retrieving the Data from User Profile Service

This section is where we pull it altogether. Back in the InfoPath main menu, select Data tab again and then
click “Form Load” button. The Rules panel will open. You need to add a rule to when the form load the query
the User Profile service. Select “New”, “Action” and then “Add” to run the action. The first action needed is

to Query for Data. Change the Data Connection to GetUserProfileByName. Click OK.

Now add a second Action. This time it will be to “Set a field’s value.” This is where all the magic happens. By calling the service and using a filter, you can display a user’s full name in a form field.

In the Rule’s Details dialog, select which field you want to display the name. In the Value section,

Select the Function button.

Click “Insert Field or Group” button and then “Show Advanced view” link on the bottom.

Change the Fields dropdown to “GetUserProfileByName” and then expand the tree view until you see “Value.”

Select the “Filter Data…” button and click “Add.” Here is where you need to specify filter conditions.

Change the first drop down to “Select a field or group” and then choose “Name” from the tree view.

Change middle dropdown to “Is equal to” and the select third dropdown to “Type in text” and add
the following text “PreferredName.” Click OK to close all your windows.

Before you publish to SharePoint, PREVIEW your form in InfoPath. Select Home tab and then Preview button. You should be able to see full name of the user.