SharePoint Saturday Canberra 2012

I had the pleasure of presenting REST services and AJAX at Canberra again.  It was a fun and sunny day that started at 4am in the morning, and packing a sleeping mr4 into the car and drive down.  Mr4 and my wife went to see the Cockington Miniature Gardens for the day, leaving me to geek out with fellow crazy SharePoint Saturday-ers.

As promised, there are a number of links:

 

Some of the comparisons I've made in the talk:

  • In SharePoint 2013, Microsoft wants you to use the services to talk to SharePoint, either via the Client Object Model, or via JavaScript and REST.  They also provide a whole lot of service endpoints for you to use:
    • /_vti_bin/listdata.svc
    • /_vti_bin/*.asmx
    • /_api/
  • In SharePoint 2010, you don't have nearly as many service end points, nor all the capabilities, but you can build custom services (which BTW, will still work in 2013).  So if you want to future-proof your solutions it is good to start thinking about implementing services and keeping the Javascript UI tier separate from the underlying services.
  • In the SharePoint 2013 Azure Workflow model, you can't deploy workflow actions.  But you are given an out of the box action that will let you call web services.  So building custom services is still a good way going forward to implement functionality that you can then reuse.
  • Re-use everywhere:
    • InfoPath
    • Workflow Web Request action
    • JavaScript AJAX

SharePoint - showing Contacts in People Search results

 

Scenario:

  • You have a working and functioning People Search page, and it's used to show information (and lovely photos) of your employees and acting as a very capable office phone book.
  • HR now wants to add more people to the list, people that, for some reason (may be they are kiosk workers, or external contractors), don't have an Active Directory account.  The phantom people.

Solution:

  • Create a standard SharePoint Contacts list
  • Include this list as part of the People search scope
  • Configure Search Metadata Properties to bring across the correct Site Columns, ultimately, showing both Real users and Contacts from Contact List in the same People Search results.

 

Create a contact list

image

 

The Contact list doesn't come with a Contact Photo by default, we should add one

 

 

Configuring Search

  • Create a new Search Scope "Humans"

    image
  • Add rules, in addition to the rule to include People, which is "contentclass = urn:content-class:SPSPeople"
    Add rule to also include Folder = http://server/Lists/Contacts

    image
  • You'll need to do a full crawl, which will pick up the Contact list, this will also pick up a crawled property for Contact_x0020_Photo
  • Then update the Scopes

 

Configure Search Page

 

  • Configure the Search Page
    • Change People Search Core Results webpart:
    • Scope: humans
    • Use Location Visualization: untick
    • Append Text To Query: scope:humans 
      (this allows your search results to show the first 20 people always, even when no query is specified)

 

Your search results should begin to show something, but it's not right:

image

  • Some fields are mapped automatically, here, the Job Title, Company, WorkPhone and Email fields have come across.  We're missing two significant ones

 

Configure Search Metadata Properties

 

  • Fix PreferredName

    image

    Add both "ows_FullName(Text) and ows_Full_x0020_Name(Text)
    Tick "Include values from all crawled properties mapped
  • PictureUrl

    image

    Add ows_Contact_x0020_Photo(Text)
    Tick Include values from all crawled properties mapped
  • Full crawl again.

 

The End result

 

image

 

Real users and Contact list entries displayed together in the search results!

XML deserialization - cannot have child contents to be deserialized as an object

Element MyValue from namespace http://schemas.datacontract.org/2004/07/Services cannot have child contents to be deserialized as an object. Please use XmlNode[] to deserialize this pattern of XML.

 

I was playing with DataContractSerializer, and getting this strange error when performing de-serialization (turning XML back into an object of type MyClass).

[DataContract]
public class MyClass
{
    [DataMember]
    public string MyName;

    [DataMember]
    public object MyValue;
}

 

The error message actually is pretty clear about what the issue is, but English is a sucky language.  Let me highlight what the error message is really saying:

Element MyValue from namespace http://schemas.datacontract.org/2004/07/Services cannot have child contents to be deserialized as an object. Please use XmlNode[] to deserialize this pattern of XML.

Read it again:

Element MyValue cannot be deserialized as an object.

 

The deserializer was actually talking about the fact that it can't turn <MyValue>1</MyValue> back into an object of the type Object.

If you change your DataContract to

[DataContract]
public class MyClass
{
    [DataMember]
    public string MyName;

    [DataMember]
    public string MyValue;
}

 

Then the deserializer will be happy.

InfoPath 2013 uses new Online Pictures instead of Clip Art

 

The InfoPath 2013 Preview doesn't really have many new features.  But this one little one made me smile.

image

In InfoPath 2013, the Clip Art ribbon is replaced with Online Pictures.

image

For those of you wondering what was there before, in InfoPath 2010 it looked like this.  Yes it's that little button that we never used.

This dialog appears when you click it.

image

 

Searching for a victim's face...

image

 

image

 

A few things would make this even more awesome:

  • Add my commonly used Clip Arts to my skydrive, and link it up.  This probably works already, except my Office 2013 Preview isn't hooked up to my normal Microsoft Account.
  • Allow additional websites, I find iconfinder.com to be extremely good.
  • Or allow URL to be used directly in the dialog.

SharePoint - The object has been updated by another user since it was last fetched - while updating Site Columns

This is the second time I've been bitten by this error.

Exception:

The object has been updated by another user since it was last fetched

 

And both times I had forgotten why, and then panicked, then searched online, found articles talking about this, and figured it all out, only to recall in the last minute...

Hey, wait a minute, this happened before.

The story begins as soon as you are trying to update your site columns.  Either via the web UI, or via code, or via PowerShell.  And then you hit this error.

The cause:

This is most likely because you've created the site column using an invalid Schema XML, in particular, you've embedded the version field in the <Field> definition.

<Field Type="Text" DisplayName="OrganisationName" Required="FALSE" EnforceUniqueValues="FALSE" Indexed="FALSE" MaxLength="255" ID="{guid-xxx}" StaticName="OrganisationName" Name="OrganisationName" Version="1" ></Field>

 

The Version attribute could have got in via a number of means, but most likely you exported the existing Schema from somewhere and it got embedded.

 

My explanation:

When you update a site column, SharePoint expects that the version number of this site column object increments after the update.  But because you are updating the site column via Schema and forcing the version to be fixed all the time, that number doesn't increment.  SharePoint now thinks there's something really wrong.

 

The Fix:

Remove the Version attribute from the Field definition, and then redeploy that definition to the server.

<Field Type="Text" DisplayName="OrganisationName" Required="FALSE" EnforceUniqueValues="FALSE" Indexed="FALSE" MaxLength="255" ID="{guid-xxx}" StaticName="OrganisationName" Name="OrganisationName" ></Field>