I have searched for a ssolution to copy a list item in a top site to a list in a subsite. Unfortunately are there no workable solution. This is the configuration
SharePoint 2013 Standard server
In the top site an Issue tracking list with customized columns for projectnumber. I want to copy a list item to a subsite with the projectnumber as the last part of the url being the projectnumber. The list in the subsite should be an issue tracking list with the same columns as the list in the topsite.
Is the best solution a workflow or a coded solution? Anyone have an example of such a solution?
Best regards,
Ove Bristrand NetIntegrate Sweden AB
Hi,
We can achieve by using the server object model.Please find the below code:
namespace CopyListItems { class Program { static void Main(string[] args) { try { SPSite mySourceSite = new SPSite("http://fivenumber:5/"); SPWeb mySourceWeb = mySourceSite.OpenWeb(); SPList mySourceList = mySourceWeb.Lists["Source List"]; SPQuery mySourceListQuery = new SPQuery(); mySourceListQuery.Query = "" + "" + "" + "" + ""; SPListItemCollection mySourceItemColl = mySourceList.GetItems(mySourceListQuery); int count = 0; foreach (SPListItem mySourceListItem in mySourceItemColl) { string SourceEmpId = mySourceListItem["Employee Id"].ToString(); string SourceEmpName = mySourceListItem["Employee Name"].ToString(); string SourceDesig = mySourceListItem["Designation"].ToString(); string SourceAge = mySourceListItem["Age"].ToString(); SPSite myDestinationSite = new SPSite("http://fivenumber:50"); SPWeb myDestinationWeb = myDestinationSite.OpenWeb(); SPList myDestinationList = myDestinationWeb.Lists["Destination List"]; SPListItem myDestinationListItem = myDestinationList.Items.Add(); myDestinationListItem["Employee Id"] = SourceEmpId; myDestinationListItem["Employee Name"] = SourceEmpName; myDestinationListItem["Designation"] = SourceDesig; myDestinationListItem["Age"] = SourceAge; myDestinationWeb.AllowUnsafeUpdates = true; myDestinationListItem.Update(); myDestinationWeb.AllowUnsafeUpdates = false; count++; Console.WriteLine(count+" item(s) copied"); } Console.WriteLine("Press enter to continue"); Console.ReadLine(); } catch (Exception ex) { Console.Write(ex); Console.WriteLine("Press enter to continue"); Console.ReadLine(); } } } }
Thanks,
ManjunathaReddy
Hi,
the MS Workflow OOTB will not do this and so you need to create an event handler but of course needs to be codedThis is one of the reasons why we are moving to K2, to get away from coding and K2 will do this quite easily
Hi, I have the same needs. Tried the REST API before X-mas but didn’t yet fully get it to work. Anyone has any updates on the matter?
br, Magnus Österberg
I will send this to my developers for them to look at and explore. It seems like this is a working solution for copying, we do want the original and the copy to remain.
I will update if we find a working solution for this need that I am sure we are most likely sharing with many others.
You may be able to use the Call HTTP Web Service action and use the SharePoint REST API to create a new list item with the same data and then delete the current item.
http://msdn.microsoft.com/en-us/library/office/dn292552%28v=office.15%29.aspx