share point saturday presentation 9 29-2012-2

30
Local Touch – Global Reach www.us.sogeti.c om Javascript-Based Solutions in SharePoint 2010 Derek Gusoff Senior Consultant Sogeti USA

Upload: derek-gusoff

Post on 15-Dec-2014

900 views

Category:

Technology


1 download

DESCRIPTION

SharePoint Saturday presentation, Detroit, Sept 29, 2012

TRANSCRIPT

Page 1: Share point saturday presentation 9 29-2012-2

Local Touch – Global Reach

www.us.sogeti.com

Javascript-Based Solutionsin SharePoint 2010

Derek GusoffSenior ConsultantSogeti USA

Page 2: Share point saturday presentation 9 29-2012-2

2www.us.sogeti.comLocal Touch – Global Reach

About Me

Derek Gusoff

Senior Consultant with Sogeti USA since 2008

@dgusoff

http://derekgusoff.wordpress.com

[email protected]

Page 3: Share point saturday presentation 9 29-2012-2

3www.us.sogeti.comLocal Touch – Global Reach

Agenda

• Why JavaScript?

• A story

• A defense of JavaScript

• jQuery (with demos!)

• Accessing data in SharePoint

– ASMX web services / SPServices

– REST interface

– Client Object Model (with demos!)

• Debugging and Troubleshooting

• The OOB JavaScript files

• Case Study

• Q & A

• The craziest thing I’ve ever done in JavaScript

Page 4: Share point saturday presentation 9 29-2012-2

4www.us.sogeti.comLocal Touch – Global Reach

Why JavaScript?

• SharePoint provides a UI right out of the box

• It doesn’t always meet all our needs

• JavaScript can fill the gap between standard functionality and your organization’s unique business requirements.

http://www.leadersintheknow.biz

Page 5: Share point saturday presentation 9 29-2012-2

5www.us.sogeti.comLocal Touch – Global Reach

A Story

http://www.learningjquery.com/

Page 6: Share point saturday presentation 9 29-2012-2

6www.us.sogeti.comLocal Touch – Global Reach

The trouble with JavaScript

http://blogs.claritycon.com/blog/

Page 7: Share point saturday presentation 9 29-2012-2

7www.us.sogeti.comLocal Touch – Global Reach

jQuery

Page 8: Share point saturday presentation 9 29-2012-2

8www.us.sogeti.comLocal Touch – Global Reach

Three things jQuery does extremely well

• Manipulate the DOM

• Make AJAX calls

• Handle Events

Page 9: Share point saturday presentation 9 29-2012-2

9www.us.sogeti.comLocal Touch – Global Reach

jQuery Selector syntax

Note: the $ function always returns an array

http://api.jquery.com/category/selectors/

Page 10: Share point saturday presentation 9 29-2012-2

10www.us.sogeti.comLocal Touch – Global Reach

jQuery AJAX calls

http://api.jquery.com/jQuery.ajax/

Page 11: Share point saturday presentation 9 29-2012-2

11www.us.sogeti.comLocal Touch – Global Reach

jQuery Events

• A simple, easy-to-use method for subscribing to events in the web page

• The ready() event – executes when the page DOM is loaded

• An example of a click handler

• http://api.jquery.com/category/events/

Page 12: Share point saturday presentation 9 29-2012-2

12www.us.sogeti.comLocal Touch – Global Reach

jQuery

Demo

Page 13: Share point saturday presentation 9 29-2012-2

13www.us.sogeti.comLocal Touch – Global Reach

SharePoint JavaScript APIs

• ASMX web services

– SOAP-based

– Lots of functionality not available anywhere else

– Supposedly deprecated in SP2013 but still supported

– Search

– User Profilles

– Versions

– FBA

– Social Data

– Sites, Webs, Lists, Views, Content Types

http://msdn.microsoft.com/en-us/library/ee705814.aspx

Page 14: Share point saturday presentation 9 29-2012-2

14www.us.sogeti.comLocal Touch – Global Reach

ASMX Web Services

Page 15: Share point saturday presentation 9 29-2012-2

15www.us.sogeti.comLocal Touch – Global Reach

SPServices

• Third-party jQuery-based library for SharePoint

• Available at http://spservices.codeplex.com/

• You can think of it as a wrapper for the ASMX web services but it’s more than that.

Page 16: Share point saturday presentation 9 29-2012-2

16www.us.sogeti.comLocal Touch – Global Reach

SPServices

Page 17: Share point saturday presentation 9 29-2012-2

17www.us.sogeti.comLocal Touch – Global Reach

REST Interface

• A RESTful way to access SharePoint List data

• The REST interface has been completely replaced in SP2013, so any 2010 development will need to be redone after upgrade to 2013.

• URL-based syntax

Page 18: Share point saturday presentation 9 29-2012-2

18www.us.sogeti.comLocal Touch – Global Reach

REST Interface

Page 19: Share point saturday presentation 9 29-2012-2

19www.us.sogeti.comLocal Touch – Global Reach

Client Side Object Model (CSOM)

• Provides a programming interface familiar to .NET developers

• The preferred method for interacting with SharePoint in JavaScript in 2010 and 2013

• Uses a web service called Client.svc under the hood.

• Asynchronous operation

• Limitations

– Unlike REST or ASMX, the CSOM is scoped to a site collection

– Limited to operations within a site collection

Page 20: Share point saturday presentation 9 29-2012-2

20www.us.sogeti.comLocal Touch – Global Reach

Client Side Object Model (CSOM)

Page 21: Share point saturday presentation 9 29-2012-2

21www.us.sogeti.comLocal Touch – Global Reach

Client Side Object Model (CSOM)

Demos

Page 22: Share point saturday presentation 9 29-2012-2

22www.us.sogeti.comLocal Touch – Global Reach

Debugging tools and techniques

• Internet Explorer Developer Tools (F12)

• Visual Studio

• Fiddler

Page 23: Share point saturday presentation 9 29-2012-2

23www.us.sogeti.comLocal Touch – Global Reach

Provisioning JavaScript to SharePoint

“The evolution of a SharePoint Developer”

• Content Editor Web Part

• SharePoint Designer

• Visual Studio Solution package

Page 24: Share point saturday presentation 9 29-2012-2

24www.us.sogeti.comLocal Touch – Global Reach

Referencing JavaScript files in SharePoint pages

• <script> tag in page

• <script> tag in Master page

• <CustomAction Location=“ScriptLink”

• Try to put commonly used functionality in common files referenced across the site

• Try to put page-specific code in files referenced only in that page or pages

Page 25: Share point saturday presentation 9 29-2012-2

25www.us.sogeti.comLocal Touch – Global Reach

OOB SharePoint JavaScript files

• To view debug version of SharePoint’s JavaScript files:

• Modify this element on the web app’s web.config:

• <compilation batch="false" debug="true">

• Interesting files to check out;

• Core.js

• SP.js

– The “SP.*js” files represent the client object model

• Init.js

• Form.js

Page 26: Share point saturday presentation 9 29-2012-2

26www.us.sogeti.comLocal Touch – Global Reach

Reference Implementation: Filtered Lookups

Requirements

• Need a way to filter lookups by user-entered criteria

• Also need a default search filter( only open projects, for example)

• Need to support a variety of search operators(Equal, Not Equal, Contains)

• NO Code allowed

Page 27: Share point saturday presentation 9 29-2012-2

27www.us.sogeti.comLocal Touch – Global Reach

Filtered Lookups – Design considerations

• The list architecture for lookups does not need to change – only the user interface• We only need to change the user interface(manipulate the DOM)

• We need a way to generate (on the fly) a query, merge it with a default query, send it to SharePoint, and process the results

• We can use jQuery to hide the default lookups and replace with our own

• We can launch a form in a dialog to capture the user’s query

• We can use the Client Object model to create our query, fetch the desired results and place them back into the form

Page 28: Share point saturday presentation 9 29-2012-2

28www.us.sogeti.comLocal Touch – Global Reach

Filtered Lookups

Demo

Page 29: Share point saturday presentation 9 29-2012-2

29www.us.sogeti.comLocal Touch – Global Reach

The craziest thing I ever did with JavaScript

http://blogs.claritycon.com/blog/

Page 30: Share point saturday presentation 9 29-2012-2

www.us.sogeti.com

Local Touch – Global Reach

Thank you