Thursday, July 28, 2011

Client Object Model – Part 4

We are going to see more about client object model with respect to ECMA script for SharePoint. If you have not gone through part 1 to part 3, I would recommend you reading them first and then continue reading from here.

This post is continuation to last part 3. As I have mentioned in the last post, that because we do not get intellisense for methods for ECMA script, we need to know what are the methods available for us. We used get_title() and get_description()as an example in last post. There are many more methods available not only for web also for lists, views and for every object that exist in SharePoint just like we have all of them for server side API.

The main problem is where to get it from? How to know names of those methods? Other problem is they are case sensitive, so we have to be extra careful.

To get all properties available for specified object, open a SharePoint site and then navigate to your page where you have added a code to get title and description of current web in content editor web part in internet explorer.

Now I have Internet Explorer 9 so I pressed Alt key, clicked on Tools menu and click on F12 Developer tools or simply press F12 key to get developer tools.

If you have IE7 or IE8, then also there should be an option for tools menu and then go to developer tools option.

After getting developer tools, you should be able to view source code in the developer pane. There are different tabs in the window as well. We are interested in scripts tab. This tab shows you all the scripts in the page. If you have loaded any of the JavaScript files instead of writing a code in content editor then you should be able to locate those functions in the file here in this tab.

Check out the code written by us and locate it.

We want to see all properties related to web, so right click the line and select insert breakpoint.

currentweb = currentcontext.get_web();

Hit start debugging

You will find breakpoint comes and waits so that we can step through each line.

Hover the mouse on it and check out all properties by scrolling down the entire list.

Same way you can get all properties of site, list, views, groups etc. objects of SharePoint and then you know what to use while you code in script.

Hope this helps. Have happy finding properties. Read Part-5 for more reading.

1 comment:

Anonymous said...

Super awesome trick. Thanks Kings.

Share your SharePoint Experiences with us...
As good as the SharePointKings is, we want to make it even better. One of our most valuable sources of input for our Blog Posts comes from ever enthusiastic Visitors/Readers. We welcome every Visitor/Reader to contribute their experiences with SharePoint. It may be in the form of a code stub, snippet, any tips and trick or any crazy thing you have tried with SharePoint.
Send your Articles to with your Profile Summary. We will Post them. The idea is to act as a bridge between you Readers!!!

If anyone would like to have their advertisement posted on this blog, please send us the requirement details to