Saturday, June 29, 2013

Alerts Timer Job Failure SharePoint 2010

After migrating to SharePoint 2010 from MOSS 2007, we faced issues of alerts not being sent. Many users reported the issue and it was an intermittent issue. It was failing for few lists. Even if there are two lists on a site, alerts from one list are working fine, but the other list was failing to send notifications.

I checked the ULS logs and it has entries for COM exception.

Timestamp    : 6/22/2013 8:30:01 AM
Continuation : False
Process      : OWSTIMER.EXE (0x1D64)
ThreadID     : 8464
Area         : SharePoint Foundation
Category     : Alerts
EventID      : c6f5
Level        : Verbose
Message      : AlertsJob, Filter for Immediate subscription with id {2D5D9F07-D0CE-478F-BFBD-B05AE9C8D337} matched event with Id 11471939
Correlation  : aa6f068e-da75-44ff-bcb1-9ef3313dccde
Context      : {}

Timestamp    : 6/22/2013 8:30:01 AM
Continuation : False
Process      : OWSTIMER.EXE (0x1D64)
ThreadID     : 8464
Area         : SharePoint Foundation
Category     : General
EventID      : 837l
Level        : Exception
Message      : An unhandled exception occured. Watson will be invoked.
Correlation  : aa6f068e-da75-44ff-bcb1-9ef3313dccde 

Exception stack trace:
at Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx)
at Microsoft.SharePoint.Library.SPRequest.DispatchTimerJob(Int32 lJobType, Guid gVServerId, Int32 lScope, Guid gDatabaseId, String bstrDSNServer, String bstrDSNDatabase, String bstrDSNUser, String bstrDSNPassword)
at Microsoft.SharePoint.Administration.SPNativeDatabaseJobDefinition.Execute(Guid targetInstanceId)
at Microsoft.SharePoint.Administration.SPTimerJobInvokeInternal.Invoke(SPJobDefinition jd, Guid targetInstanceId, Boolean isTimerService, Int32& result)

The common thing in these errors was "it was throwing exception after applying filter for immediate subscription as highlighted above.

I first located the alert by using PowerShell script given below. I used the script for web application on which the timer job was failing.

$webs=Get-SPWebApplication <webappurl>|Get-SPSite -Limit All| Get-SPWeb -Limit All
$alert=$webs|%{$_.Alerts}|?{$_.Id -eq "<subscriptionid>"}
$alert|Select @{Name="User";Expression={$_.User.LoginName}}, List, @{Name="Url";Expression={$_.List.ParentWeb.Url}}

The script listed the "SharePoint\System" account as user. This was weird and so we verified on the site "is it really a system account subscribing the alerts?". Yes., it was "System Account."

System account cannot subscribe to alerts in SP2010. We were not sure whether it was possible in MOSS 2007. System account do not have Email ID and so we cannot subscribe to alerts using System Account. This was causing the failure of the Immediate Jobs timer job.



The timer job was failing for the lists where system account had subscription and for other lists it was working.

We removed all system account subscription on all sites in the web application and there were no failures any more.

Hope this will help others.

Sunday, May 26, 2013

Display Form returning 404 Not Found in a List created from Custom List Template

Recently one of the SharePoint site user complained that display form of a list is not working. We checked the list and everything was properly set (DefaultDisplayFormUrl ), but still it was not working. The list was created from a custom list template. The list template was based on an existing list (original list). The original list is working fine but the new created from the template was returning "404 Not Found" error.

I opened turned OFF the dialog and checked the URL it uses to launch display form. As the normal list behaves, it is first invoking the "listform.aspx" page with  query string. The "listform.aspx" page normally causes redirection to appropriate page type specified in the query string. Due to the 404, browser was not displaying the correct final URL. So I just launched the developer tools and checked the HTTP request/response cycle.

The "listform.aspx" is sending 302 for redirection but the location it was referring to the original list. As the original list does not have the new created display form of the new list. It was returning 404.

Then we removed content type ID from the query string and it was working fine. We further investigated and checked if it refers to wrong content type. It was referring to the content type available with the new list. So content type is not the issue.

Why "listform.aspx" referring to the original list?

I de-compiled the code of the "listform.aspx". The "listform.aspx" page invokes a method of ListFormWebPart. This method prepares the final display URL  based on the "DisplayFormUrl" property of content type.


The PowerShell script confirmed it that the problem is with the content type display form URL. The content type is right but it's property has wrong reference.

$web=Get-SPWeb http://
$list=$web.Lists[]
$ct=$list.ContentTypes[0];
$ct.DisplayFormUrl

We updated the DisplayFormUrl in script and it started working. Great job!!!

Monday, March 25, 2013

Lists.asmx: Method not Found


Recently we had an intermittent issues with lists.asmx. It was giving us SoapServerException as below:
Method not found: 'Microsoft.SharePoint.Utilities.SPChunkedStringBuffer Microsoft.SharePoint.SPListItemCollection.GetXmlInternal(Boolean, System.Collections.Hashtable, Boolean, Boolean)'.

The issue was occurring infrequently. We located the issue on two WFE machines.

The exception was saying "Method not found." This is little weird as how OOB dll file miss this method and what is the DLL it is referring to.

I opened the lists.asmx and found that it refers to STSSOAP.DLL.


I searched for the DLL file and we located at two different locations : 1. SharePointRootFolder\ISAPI 2. WebApplicationVirtualDirectory\_app_bin

While browsing through these directories I noted that the DLL files have different "Modified Date". We checked the other WFEs and this difference was not present there. The both files had different versions as "14.0.6024.1000" and "14.0.6122.5000". We recently had server patching and somehow this web application _app_bin folder had the old file and using it.

We replaced the DLL with latest version and the issue is resolved. :)


Monday, October 29, 2012

SharePoint 2013 REST Service

SP 2010 is the first version of SharePoint which supports REST API/Service (REpresentational State Transfer). SP 2010 has REST located at http://[web site URL/_vti_bin/ListData.svc.

SharePoint 2013 has few changes related to REST access URL. SP 2013 has REST located at http://[web site URL]/_api/.

SharePoint 2013 REST endpoints map to SharePoint Client object model types and members. As we know that, SharePoint Client Object Model allows access to various objects in the hierarchy down from the Site Collection i.e. Site (Site Collection), Web (Web Site), List, ListItem etc.

Similarly, the SP 2013 REST allows access to object Site and the objects below it in the hierarchy.

SP 2010 REST API was allowing access to only lists and their items in a web site. SP 2010 REST never given access to Site or Web objects whereas SP 2013 REST can access these objects as well.

Let us see how REST works and how the REST endpoints are formed.


Access Site Collection Object and its properties

http://[Web Url]/_api/site

Use above URL format to access the site collection object in Atom feed format. Do you re-collect “Site” object in Client Object Model representing site collection? Here we used the same object after “_api/”.

Web URL can be any web site in the site collection. Site object can be accessed from any web site in the site collection.

Look at the below XML response for the site collection object.


 
There are two XML namespaces “m:” and “d:” representing metadata and data namespaces respectively.  Complex types and collections are represented as Atom feeds in REST and belong to default namespace. The properties with primitive types belong to “<m:properties>” node.

The “term” attribute on the “<category>” node has value set to fully qualified name of the type of Client Object Model.

The <link> node represents the collections and complex type properties of the object. The “href” attribute provides the /site relative URL to access the atom feed for collection/complex type.

e.g. To access Root Web of the site collection, use

http://[web URL]/_api/site/RootWeb

Similarly one can access the primitive properties by appending the name property in URL after “/site/”. The response is not in Atom feed format. It is just a XML fragment. e.g. To know if the site collection allows use of SharePoint Designer, use

http://[web URL]/_api/site/AllowDesigner

The properties presented in REST response do not contain all properties of “Site” type. e.g “Site” has property “Usage”. There is no <link> node for it in the response, but we can access the property using below URL.
http://[web URL] /_api/site/usage

Access Web site and its properties
http://[Web Url]/_api/web

The above REST endpoint lets us access the basic Web object of Client Object Model.
 
To read web “Title”, use

http://[web URL]/_api/web/title
To read lists collection in a web site, use

http://[web URL]/_api_web/lists

The response from above REST endpoint contains nodes for each list/library in the web site. You can access the specific list, using the <id> node value inside the specific list’s entry.

To read the specific list details, use
http://[Web Url]/_api/web/Lists(guid'[Guid of the list]')

To access the items of a list, use
http://[Web Url]/_api/web/Lists(guid'[guid of the list]')/Items

To access an item with specific ID, use
http://[Web Url]/_api/web/Lists(guid'[guid of the list]')/Items([id of the item])

Thursday, October 4, 2012

Related List /Items View in SharePoint 2010

SharePoint 2010 has an enhancment to show related list views. There is pre-requisite to make it work. You should have lists with relation established using lookup columns.

Let's try it.

1. Create a custom list named "Country". We will use "Title" column. If you want to add any new columns, you can do so.

2. Create one more list named "City". Create the columns as shown below. The "Country" must be a lookup column to "Country" list.

3. Add some city information to the list.

4. Right-click on any city and click "Open in New tab/Window". This way it will launch the display form in browser window. This will make "Site Actions" menu available. The "Site Actions" menu is not available in dialog. Click "Site Actions" -> Edit Page.

Click inside the existing web part zone. The ribbon starts presenting "Page Tools" tab. It has a button "Related List". Click it. It shows the all related list. In our case, it is city.

5. Click on the related List "City". It added a related items view as shown below. It will only show cities for the selected country. i.e. the country for which display form is shown.

6. Do not forget to click "Stop Editing" in the "Page" tab of ribbon. This actually saves the page with changes.

7. User can add items to the related list using related items web part. Click the "Add new item" link and it starts showing add new item form page for the "City" list. You can add item here. If the Country display form (View Properties) is being preseneted for "India", still you can add item for "Japan" from this screen. Be careful.


8. You can change the view of related list items. You can add/ remove column from the view using "Edit the current view" link or selected the appropriate view from the drop-down.

9. Edit the current view, after saving view changes takes back to the display form which will show nothing. So close the browser tab/window and reopen. You can see the changes.

Using SPD 2010:

1. Create a new view "DetailedView" for Country list. The view must be same as All Items view.
2. Check-out the page in SharePoint Designer 2010. To accomplish this, open the list using All Files option in SPD 2010.
3. Right-click the page and click on "Edit in Advanced mode".
4. In "Design" view, click inside the available web part zone. Put the cursor at a location where you want to add the related list items web part.
5. Click "Insert" tab in ribbon and it has a button called "Related Item View". This button presents all related lists as shown below.

6. Click the "City:Country" and it adds the related items view on the page as below. Save the page and check -in
7. The view page on browser refresh starts showing a new column as shown below to select an item and the related items are shown for the selected item. Selected item has dark black arrow icon.
 


I will suggest to use browser based method as it will avoid the un-ghosting of the page. But if you would like to customize the XSL of related items web part, better to use SharePoint Designer.

Saturday, September 29, 2012

My First Look at SharePoint 2013 Site

[The content is specific to SharePoint 2013 Preview. The RTM may come up with some changes.]

SharePoint 2013 - I was waiting for you. Yes, today I started working on SharePoint 2013 (Preview) site.

I put the URL in browser and this is what I see on home page.


I have highlighted few parts in the picture. These are new in the UI and are not self-explanatory.

Let us have a look at each one.

Edit Links

What links are they talking about? Do they mean page links? Can we re-organize or update page links? Why duplicates are placed at top and below left navigation? Too many questions... came to my mind. Let's give it a try.

Click "Edit Links" in the top. The UI changes in-place as below.

I clicked the "+" sign and it presented me with screen below. It asks for the "Text to be displayed as link" and the target URL.

Can't I specify the target to open the link in new window? There is no way. This a Global navigation, use it only for links scoped to the content in the site collection.

Click "OK". It added a link in Global navigation. But the link is not saved... we have to click on "Save".

Here is how it looks after saving.

Can I edit the link? Yes, I can. Click on "Edit Links" and then click on the link itself. It presents the below screen changes. Click on "Link" icon which is similar to infinity symbol.

It allows to update the link. (Note: This applies to only saved links. If you have added a link but not saved and before saving you want to edit. It does not allow to do it.)

So the duplicate below left navigation...it updates the links in left navigation and it should contain links scoped to the site level content.

Focus On Content

There is an icon on right side at the top icons collection. On hovering the icon, it displays a tooltip saying "Focus on content".

I clicked it...the left navigation bar disappeared. I again clicked it, the left navigation re-appeared. This is really good. Rather than the navigation items occupying the real-esate of screen, it will become available for content. User will have a better experience while working with the content. When required, user can invoke the navigation on demand. Really, cool...!

Stay tuned...!more stuff coming up about SP 2013.

(The screen-shots are from Office 365 Preview site. There is not much difference in the UI of actual SharePoint 2013 site. So the notes apply to SharePoint 2013 Preview site.)

Sunday, September 23, 2012

List the "vti_" properties using PowerShell

Every file/document in SharePoint possess some meta-info. It is stored in hashtable presented by SPFile.Properties property. Most of the properties start with "vti_". We cannot write the "vti_" properties as they are read-only.

But we can use this property-bag store custom meta-property for the file. We can manage the custom properties using below method:
  • SPFile.AddProperty
  • SPFile.SetProperty
  • SPFile.GetProperty

SPFile.CustomizedPageStatus property determines the customization status of wiki page or page layout using below properties.
  • vti_setuppath
  • vti_hasdefaultcontent
Different SharePoint objects has the hashtable based property to store these kind of properties. e.g SPWeb.AllProperties. SPWeb.AllProperties["__PagesListId"] stores the GUID value of "Pages" library created on activating publishing feature.

Changing the UIVersion of migrated sites automatically updates the master page to appropriate UIVersion. This is possible because of the SPWeb.AllProperties. It stores the master page details related to each UIVersion.

PowerShell script to list the "vti_" properties of a file.

$web=Get-SPWeb <webSite URL >
$list=$web.Lists["Site Pages"]
foreach($item in $list.Items)
{
    $item.File.Name
    Write-Host "**********"
    foreach($key in $item.File.Properties.Keys)
    {
        Write-Host $key "=" $item.File.Properties[$key]
    }
    Write-Host "------------------*****---------------------------"
}

PowerShell script to list "vti_" properties of web site.

$web=Get-SPWeb <webSite URL >
foreach($key in $web.AllProperties.Keys)
{
     Write-Host $key "=" $web.AllProperties[$key]
}

Have a look!