Home » ActionScript 3.0, Flex, Sharepoint

Add, Update, delete SharePoint List Item in Flash CS5 and Flex4

9 March 2011 8 Comments
Share on Facebook

In Previous article we have learnt how to read and write query to retive informations of SharePoint 2010 Lists. First download and setup the SharePoint Connector library, Here we are going to do more process on SharePoint List are the following.

  • Add an Item in SharePoint List.
  • Update an Item.
  • Delete a SharePoint List item.

The Add, Delete and Update Process are the same as we do in a Database, but we are going to perform the same in a SharePoint List instead of Database Table.

SharePoint List Operations:

Make a call to updateList Method of SharePoint Connector to Adds, deletes, or updates the specified items in a list on the current site.

_sharepoint.updateList( handleUpdateList, "listName", {Cmd:COMMAND, Fields.. } )

Parameters:

handleUpdateList: Handles the result XML.

ListName: A string that contains the name of the list. It is recommended that you use the list GUID surrounded by curly braces (i.e., “{GUID}”), but you can also use the list display name.

Command: Three commands to be used with are

  1. Cmd:UpdateList.NEW – to add a new row in sharepoint list.
  2. Cmd:UpdateList.UPDATE – to add a new row in sharepoint list.
  3. Cmd:UpdateList.DELETE – to add a new row in sharepoint list.

Fields: Datas in ColumnName: Data combination

Cmd:UpdateList.NEW:

_sharepoint.updateList( handleUpdateList, "Country", {Cmd:UpdateList.NEW, Title:'9,596,960 (sq km)',Country:'China', Capital: 'Beijing', GDP:'8,789,000,000,000 (USD)', Population:'1,330,141,295' } )

Above adds new row to the SharePoint List that we have provided.

Cmd:UpdateList.UPDATE:

Each row in SharePoint list item has unique ID, We are going to pass the ID of a row when update and delete operations. Remember the primary key in Database.

_sharepoint.updateList( handleUpdateList, "Country", {Cmd:UpdateList.UPDATE, ID:4, Title:'updated data here'} )

Here

  • ID: 4 is the row key
  • Title is the Column name follow by the data to be updated after colon

Cmd:UpdateList.DELETE

_sharepoint.updateList( handleUpdateList, "Country", {Cmd:UpdateList.DELETE, ID:9} )

SharePoint List Operations using Flash CS5:

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

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 ){
	_sharepoint.updateList( handleUpdateList, "Country", {Cmd:UpdateList.NEW, Title:'9,596,960 (sq km)',Country:'China', Capital: 'Beijing', GDP:'8,789,000,000,000 (USD)', Population:'1,330,141,295' } )
	//_sharepoint.updateList( handleUpdateList, "Country", {Cmd:UpdateList.UPDATE, ID:4, Title:'updated data here'} )
	//_sharepoint.updateList( handleUpdateList, "Country", {Cmd:UpdateList.DELETE, ID:9} )

}

function handleUpdateList( xml:XML ){
	trace("Response XML:"+xml)
}

Note: I have used List name instead of GUID
Country == %7B4D186B07%2DA36C%2D4A17%2D89E6%2DE433F279AC16%7D
We shall either use List Name or GUID.

SharePoint List Operations using Flex / Flash builder:

<?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 com.sharepoint.services.*; 

			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.updateList( handleUpdateList, "Country", {Cmd:UpdateList.NEW, Title:'9,596,960 (sq km)',Country:'China', Capital: 'Beijing', GDP:'8,789,000,000,000 (USD)', Population:'1,330,141,295' } )
				//_sharepoint.updateList( handleUpdateList, "Country", {Cmd:UpdateList.UPDATE, ID:4, Title:'updated data here'} )
				//_sharepoint.updateList( handleUpdateList, "Country", {Cmd:UpdateList.DELETE, ID:9} )

			}

			private function handleUpdateList( xml:XML ):void{
				Alert.show("Response XML:"+xml)
			}

		]]>
	</fx:Script>

</s:Application>

Note:

If you edit the default “Title” column name (Here I edited as Area). Use “Title” Column name in code.

Conclusion:

We have seen how to update, add and delete row items in a SharePoint List using SharePoint Connector class.

Download SharePoint Connector Sample Files

 

GET THE UPDATES VIA EMAIL

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


  • sirajuden

    HI

    When i access to read the data from its perfect..
    same time i try to update list its give error…

    Error opening URL ‘htp://eworkspace/teamsites/BS/Demo/_vti_bin/lists.asmx’
    Error #2044: Unhandled ioError:. text=Error #2032: Stream Error. URL: htp://eworkspace/teamsites/BS/Demo/_vti_bin/lists.asmx
    at com.sharepoint.utils.alducente.services::WSProxy/callService()
    at com.sharepoint.utils.alducente.services::WSProxy/callMethod()
    at com.sharepoint.utils.alducente.services::WSMethod/myMethod()
    at com.sharepoint::SharePointConnector/updateList()
    at Update_fla::MainTimeline/handleReturnedeList()
    at Function/http://adobe.com/AS3/2006/builtin::call()
    at com.sharepoint.services::ReadList/handleXMLData()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at com.Manager::XMLManager/handleXMLLoaded()
    at flash.events::EventDispatcher/dispatchEventFunction()
    at flash.events::EventDispatcher/dispatchEvent()
    at flash.net::URLLoader/onComplete()

    regards
    sirajudeen

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

    sirajuden,

    Share the code how you are trying to update the List..

    -saravanan

  • Adam

    Sirajuden,

    I was having the same exact problem. My personal mistake was that I was using the “%7B4D186B07%2DA36C%2D4A17%2D89E6%2DE433F279AC16%7D” string for the list as opposed to the “{…}” or the actual list name (which works fine). Once I made this correction, problem solved.

    Not sure if that’s your problem but this is what worked for me.

    V/r

    Adam

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

    you are correct Adam.

    Sirajudeen,

    try to pass the List name here

    _sharepoint.updateList( handleUpdateList, “your list name”, {, {Cmd:UpdateList.NEW, Title:’9,596,960 (sq km)’,Country:’China’, Capital: ‘Beijing’, GDP:’8,789,000,000,000 (USD)’, Population:’1,330,141,295′ })

    If you edit the default “Title” column name (Here I edited as Area). Use “Title” Column name in code. Instead of Area.

    -Saravanan

  • Adam

    Hey Saravanan,

    Do these connector classes work with the picture library as well? Just curious

    Thanks again for everything!

    Adam

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

    Adam,

    I did not check with picture library, hope it works..

    -Saravanan

  • sirajudeen

    Hi

    Thanks for all replay to me
    Now its working

    one another thing how can i get userid

    _vti_bin/usergroup.asmx

    how can i fetch the userid from the usergroup

    kind regards
    sirajudeen

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

    Will add it soon

    :)