Home » ActionScript 3.0, Flex, Sharepoint

Read/Retrive SharePoint 2010 List in Flash CS5, Flash Builder(Flex4)

9 March 2011 17 Comments
Share on Facebook

The first part of the tutorial guides you to set up the SharePoint AS3 Connector library and how to connect with SharePoint website using Flash and Flash Builder(Flex 4). In this tutorial you will learn how to retrive data from a SharePoint list and display as XML structured data.

Introduction:

What is SharePoint List?

Lists in SharePoint resemble database tables in structure and behavior. Lists support various field or data types, and supports actions like creating, updating or deleting items.

XML driven components are a favorite among Flash and Flex developers, it facilates easy maintaineance. But the advantage of a SharePoint List has upper hand, you can pull the SharePoint list data as XML and render inside Flash or Flash Builder(Flex4).

We are not going discuss in deep about SharePoint List, instead we will discuss

  • How to read a SharePoint 2010 List in Flash and Flex.
  • How to query a SharePoint 2010 list using SharePoint as3 Connector.

Before Going to tutorial:

Create a SharePoint list in the SharePoint 2010 services site, Here I have create a SharePoint 2010 list already created.

SharePoint 2010 List

To Get the SharePoint List ID:

We need SharePoint List id / GUID to process a list. Follow the steps to get the List ID:

1. Click on the List from the SharePoint site.

2. Click on List under List Tools

3. And Select List Settings from the Menu and find the GUID from the URL

Below is the URL of my SharePoint List:

http://ea.sharepoint.designscripting.com/teams/CONNECTOR/_layouts/listedit.aspx?List=%7B4D186B07%2DA36C%2D4A17%2D89E6%2DE433F279AC16%7D

And the list id is “%7B4D186B07%2DA36C%2D4A17%2D89E6%2DE433F279AC16%7D

Read SharePoint List in Flash CS5:

To retrive a data using SharePoint as3 Connector is simple, just pass the List ID to getList method of SharePoint connector.

_sharepoint.getList( handleReturnedeList, "%7B4D186B07%2DA36C%2D4A17%2D89E6%2DE433F279AC16%7D","" );
  • handleReturnedList is the function which returns the result XML
  • Second parameter is the SharePoint List GUID
  • Third parameter is to Query the SharePoint List. We explained at end of the tutorial.

Entire code for Read SharePoint List in Flash:

import com.sharepoint.SharePointConnector;
import com.sharepoint.events.SharepointEvent;

var _sharepoint:SharePointConnector = new SharePointConnector();
_sharepoint.connect( "http://ea.sharepoint.designscripting.com/teams/CONNECTOR" );
_sharepoint.addEventListener( SharepointEvent.CONNECTED, handleConnectedEvent );

function handleConnectedEvent( e:SharepointEvent ):void
{
	trace( "Sharepoint Connected:::"+e.connected );
	_sharepoint.getList( handleReturnedeList, "%7B4D186B07%2DA36C%2D4A17%2D89E6%2DE433F279AC16%7D","" );
}

function handleReturnedeList( xml:XML ){
	trace("getList:::"+xml);
}

Entire code to retrive SharePoint List in Flex:

<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
			   xmlns:s="library://ns.adobe.com/flex/spark"
			   xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" creationComplete="init()">
	<fx:Script>
		<![CDATA[
			import com.sharepoint.SharePointConnector;
			import com.sharepoint.events.SharepointEvent;

			import mx.controls.Alert;

			private var _sharepoint:SharePointConnector;

			private function init():void
			{
				_sharepoint = new SharePointConnector();
				_sharepoint.connect( "http://ea.sharepoint.designscripting.com/teams/CONNECTOR" );
				_sharepoint.addEventListener( SharepointEvent.CONNECTED, handleConnectedEvent );
			}

			private function handleConnectedEvent( e:SharepointEvent ):void
			{
				Alert.show( "Sharepoint Connected:::"+e.connected );

				_sharepoint.getList( handleReturnedeList, "%7B4D186B07%2DA36C%2D4A17%2D89E6%2DE433F279AC16%7D","" );
			}

			private function handleReturnedeList( xml:XML ):void{
				Alert.show("getList:::"+xml);
			}
		]]>
	</fx:Script>

</s:Application>

XML Output:

Sample output for the SharePoint List I have used from handleReturnedeList handler.

<data>
    <row ID="5" LinkTitle="3,287,590 (sq km)" Country="India" Capital="New Delhi" GDP="$3,560,000,000,000 (USD)" Population="1,173,108,018" Attachments="0" xmlns="#RowsetSchema"/>
    <row ID="6" LinkTitle="9,631,418 (sq km)" Country="US" Capital="Washington, DC" GDP="$14,260,000,000,000 (USD)" Population="310,232,863" Attachments="0" xmlns="#RowsetSchema"/>
    <row ID="7" LinkTitle="244,820 (sq km)" Country="UK" Capital="London" GDP="$2,149,000,000,000 (USD)" Population="61,274,806" Attachments="0" xmlns="#RowsetSchema"/>
    <row ID="8" LinkTitle="377,835 (sq km)" Country="Japan" Capital="Tokyo" GDP="$4,137,000,000,000 (USD)" Population="126,804,433" Attachments="0" xmlns="#RowsetSchema"/>
  </data>

CAML Query to retrive SharePoint List Data in Flash / Flex:

Instead of retriving the entire SharePoint list as XML, We can retrive particular row item of the SharePoint list.

To Query and Read particular item data from SharePoint List:

In this Section we will learn how to query and retrive data from SharePoint List using CAML(Collaborative Application Markup Language) is an XML-based query language that helps you querying, building and customizing Web sites based on Windows SharePoint Services.

Note: Below is a CAML query to retrive row item where ID = 6

http://ea.sharepoint.designscripting.com/teams/CONNECTOR/_vti_bin/owssvr.dll?Cmd=Display&List={4D186B07-A36C-4A17-89E6-E433F279AC16}&XMLDATA=TRUE&query=ID&FilterField1=ID&FilterValue1=6

Make sure the List GUID and the Column name and value is correct, then open this URL in a browser.

Using SharePoint Connector:

_sharepoint.getList( handleReturnedeList, "%7B4D186B07%2DA36C%2D4A17%2D89E6%2DE433F279AC16%7D","&query=ID&FilterField1=ID&FilterValue1=6")

Conclusion:
We have learnt how to read data from SharePoint List and writing query SharePoint List data using SharePoint Connector Libary.

Download SharePoint Connector Sample Files

 

No related posts.

GET THE UPDATES VIA EMAIL

We don't share your email anywhere, grab our rss via feedburner


  • adam

    HI, first of all thanks so much for sharing this tutorial. It’s a godsend.

    I have a problem though: I can connect to my sharepoint site just fine, but it’s throwing an error ( #1009) whenever I try to fetch a list. Any thoughts?

    thanks so much!

  • http://www.designscripting.com/ admin

    Adam,

    Make sure u pass the right list GUID.

    _sharepoint.getList( handleReturnedeList, “your GUID Here”,”");

    Hope it will help u..

    -Saravanan

  • adam

    Saravanan,

    Hello. I passed the right GUID , I even tried it with different SharePoint list GUID’s and various browsers (firefox, ie6, etc)

    I did some extra research and found out that I may need to put a cross-domain policy for Flex/Flash on the sharepoint root. Have you done this already? I’m starting to think it may have been a critical stepped I may have missed, I’m still a bit new to all this.

    Thanks again for everything,

    -Adam

  • http://www.designscripting.com/ admin

    Adam,

    Pls share the Error message and SharePoint GUID here.

    -saravanan

  • adam

    Hi Saravanan,

    Below is the error code. As much as I’d like to post the GUID, I have to refrain from posting it publicly due to the data contained.

    I have tried it with multiple GUID’s within the site and I get the same error. All my GUID’s follow the “%7B4D186B07%2DA36C%2D4A17%2D89E6%2DE433F279AC16%7D” format that you have above. Again, thanks for the time you spent making these classes. I’ve gotten along farther then I ever thought I would just being able to connect :)

    TypeError: Error #1009: Cannot access a property or method of a null object reference.
    at SharepointTestingNumber2/handleConnectedEvent()[C:\Documents and Settings\*****\My Documents\Flex Builder 3\SharepointTestingNumber2\src\SharepointTestingNumber2.mxml:32]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at com.sharepoint::SharePointConnector/connected()[C:\Documents and Settings\******\My Documents\Flex Builder 3\SharepointTestingNumber2\src\com\sharepoint\SharePointConnector.as:54]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at com.sharepoint.utils.alducente.services::WebService/wsdlComplete()[C:\Documents and Settings\******\My Documents\Flex Builder 3\SharepointTestingNumber2\src\com\sharepoint\utils\alducente\services\WebService.as:53]
    at com.sharepoint.utils.alducente.services::WSDL/wsdlLoaded()[C:\Documents and Settings\******\My Documents\Flex Builder 3\SharepointTestingNumber2\src\com\sharepoint\utils\alducente\services\WSDL.as:53]
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/onComplete()

  • http://www.designscripting.com/ admin

    Adam:

    Error #1009: Cannot access a property or method of a null object reference.

    means we are trying to access which is not defined…

    So please try to download the samples directly from

    http://code.google.com/p/sharepoint-as3-connector/downloads/detail?name=Samples-SharePointConnector.zip

    then change the GUID and sharepoint URL path..

    Hope this works..

    -saravanan

  • Adam

    Figured it out,

    For some reason the sharepointConnector object wasn’t remaining in scope for me.

    Works great , thanks a lot! Trying to use the updatelist connector now but getting the same errors as that guy on the page. I’ll try again and re-post on that blog

    -A.

  • Chris

    Does this connector allow us to access the SharePoint list anonymously on the production/public servers?

    Thanks,
    Chris

  • http://www.designscripting.com/ admin

    Chris,

    It depends on the SharePoint permissions…

    -sara

  • Jim

    First, great class here! If I can get everything connected and working, this’ll be amazing for using SP as a Flash CMS!

    Last Friday, I had this connecting, but I wasn’t able to query specific rows. All rows would still be returned. Now, after not having changed anything in my code, I can even get it to connect. It never goes into the handleConnectedEvent function, so I guess the event CONNECTED never happens. I notice there’s not been a pop-up at any point to enter my SP credentials. Should this happen? Is this the issue? Any help would be greatly appreciated! Thanks a lot

    Jim

  • Jim

    Sorry, I mean’t “CAN’T even get it to connect” above!

  • http://www.designscripting.com/ admin

    Jim,

    Try to download the source and link to your SharePoint. Whether this works then might be problem with code..

  • sirajudeen

    Hi

    I dont know how to use the query.i dont understand also how can i use the caml query?

  • mark

    Hi – this connector is heaven sent. many thanks!

    i got everything working.
    but have one problem when trying to retrieve a specific ID of data maybe you can help as i’m desperate!

    1. Using the CAML query the browser returns the correct matching ID’s xml.
    2. however if i use the sharepoint connector in flex it doesnt.
    e.g when using : _sharepoint.getList( handleReturnedViews, “%7BD50BB3C3%2D6340%2D49BE%2D876F%2DD8B3E0D554D7%7D”,”&query=ID&FilterField1=ID&FilterValue1=8″); the (protected function handleReturnedViews(xml:XML):void{}) – returns nothing.

    if i remove the specific query i.e _sharepoint.getList( handleReturnedViews, “%7BD50BB3C3%2D6340%2D49BE%2D876F%2DD8B3E0D554D7%7D”,”");
    - then it gives me the full xml.

    seems only the specific qurey is the problem. but it works fine in the browser using the filters.
    any clues where i should start looking?

    rgds

  • Paul

    Hi,ngreat article!nI can connect to the sharepoint and grab the data in Flash builder 4.5, but:nI get only the first 101 rows andnif I release the project and put it on the sharepoint server I get a null reference error, like some other people here. nAny clue?nThanks a lot!nPauln

  • Demian_m33

    Great post!!! It’s the solution to my problems.. but… does anyone knows if this work on MOSS 2007!! thanks for your help!!

  • Anonymous

    Hi Paul,nnChange the settings in Sharepoint list to maximum limit