-
February 17th, 2011, 06:04 PM
#1
[RESOLVED] Sharepoint 2010: Updating from Client Object Model
Hello everyone,
I am not sure where to post this as I didn't see a forum for SharePoint on here. I hope someone can help me with this.
I have a form sitting on a webapp outside of the sharepoint server (which is why I am using the Client Object Model). To make a long story short the form is sending data to a SP list. This list is made up of regular string fields, date fields, lookup lists, choice lists and user data.
I am able to insert data that isn't part of a list with no issues. However, when I update any of the lookup lists i receive the following error:
Invalid look-up value. A look-up field contains invalid data. Please check the value and try again.
Ok. So I then wrote code that went to the list and got the entire item as follows (please bare in mind this is not very eloquent, but it gets the data)
Code:
Public Function getListItem(ByVal job As JobPosting) As ListItem
Dim listColl As ListItemCollection
Dim listItem As ListItem
Dim caml As String = "<View><Query><Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" & job.title & "</Value></Eq></Where></Query></View>"
listColl = RetrieveSharePointList(AppConfig.SharePointSite, "JobTitle", caml)
listItem = listColl.Item(0)
Return listItem
End Function
The function RetrieveSharePointList then passes the query and list name to SP and gets the data back.
So I am able to successfully get the data but when I do the following:
Code:
Dim clientCtx As ClientContext = New ClientContext(sharePointSiteURL)
Dim spList As List = clientCtx.Web.Lists.GetByTitle(listName)
Dim listItemCreation As New ListItemCreationInformation
Dim listItem As ListItem = spList.AddItem(listItemCreation)
Dim tmplistItem As ListItem = tmpMgr.getListItem(job)
listItem("JobTitle") = tmplistItem
listItem.Update()
clientCtx.ExecuteQuery()
I receive the following error:
"The given key was not present in the dictionary."
I am really at my wits end. Does anyone have any straight forward way of adding data based on lists to SharePoint from the Client Object Model?
Thanks very much for any assistance.
-
February 17th, 2011, 11:12 PM
#2
Re: Sharepoint 2010: Updating from Client Object Model
SP must pass the KEY, hence the EQ at the end, would be my guess.
-
February 18th, 2011, 08:23 AM
#3
Re: Sharepoint 2010: Updating from Client Object Model
Managed to resolve this last night (guess I just needed to step a way for a bit).
Here's what I did.
Code:
listItem("JobTitle") = tmpMgr.getListItemID(job.title)
Code:
Private Function getListItemID(ByVal jobData As String) As Integer
Dim listColl As ListItemCollection
Dim listItem As ListItem
Dim id As Integer
Dim caml As String = "<View><Query><Where><Eq><FieldRef Name='Title' /><Value Type='Text'>" & jobData & "</Value></Eq></Where></Query></View>"
listColl = RetrieveSharePointList(AppConfig.SharePointSite, "JobTitle", caml)
listItem = listColl.Item(0)
id = listItem.Id
Return id
End Function
The update then works fine with the id or key. So I guess the solution I figured out is pretty much what you said dglienna.
Thanks.
Last edited by HawkeyeD; March 4th, 2011 at 02:55 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|