tags:

views:

145

answers:

2

Hello SO:

I am working with sharepoint and I am trying to add a service call to microsoft's call center application template. I can add one with just a name with the following code:

SPSite allSites = new SPSite(siteURL);
SPWeb site = allSites.AllWebs[siteName];
SPListItemCollection requestsList = site.Lists[serviceRequests].Items;
SPListItemCollection customerList = site.Lists[customers].Items;

SPListItem item = requestsList.Add();
item["Service Request"] = "Program Test";
//item["Customer"] = "Donald Duck";
item["Customer"] = customerList[0];
item.Update();

First I tried just using the customer name, which did not work. I then got the customer list and tried to use the customer list item instead, but I still get the same error:

"Invalid data has been used to update the list item. The field you are trying to update may be read only."

Does anyone have experience with adding information to sharepoint from code similar to this? Is there someway I can determine which fields are read-only, if any?

Thanks!

A: 

This sometime happens when you have a Lookup Field and you don't specify the value for it. For Example when you have a List with the Following item

  1. Customer : Text
  2. Department : Lookup of Department List and Required.

    SPListItem item = requestsList.Add();        
    item["Customer"] = "as";
    item.Update();
    

Now you will get this error.Because you didnt specify the value for the Department field

Kusek
+1  A: 

I found the solution to this problem, please check out this link.

Anders
You dont need to go that far to get that work. it is enough that you set the Index value to the Lookup field rather than 1#Value format.
Kusek
thanks for your input kusek
Anders