0

There's a SharePoint site I'm working on that recently got migrated over from 2010 to 2013. However, in the process it ended up causing on of the columns in a list to become uneditable in the settings. Moving forward, the plan is to recreate that column (a single-line text field) and copy the values from the old column to the new.

However, doing this will most likely cause the date modified to become today as well as kick starting the workflow associated with this list. There are also almost a thousand items in this list.

Is there a way to copy over the values between the two columns without changing the date modified and kick starting the workflow?

EDIT: I also want to add that I cannot use PowerShell in my case.

1 Answer 1

1

Create an inline aspx page in /15/template/layouts on the SharePoint server to update the column. A sample aspx page is below. It updates from one column to another in the same list. Run it on SharePoint QA with one list item id to make sure it works for you and does not trigger any workflow or updates the modified fields. Once tested, use the for loop on the list items to update all. Also make sure listItem[srcFieldInternalName] returns the existing field value correctly.

<%@ Page language="c#" enableSessionState="true" %>
<%@ Import Namespace="Microsoft.SharePoint" %>
<%@ Import Namespace="System.Collections.Generic" %>
<%@ Import Namespace="Microsoft.SharePoint.Workflow" %>

<script language="c#" runat="server">
protected void Page_Load(object sender, System.EventArgs e)
{
    using (SPSite oSiteCollection = new SPSite("site_url"))
    {
        using (SPWeb oWebsite = oSiteCollection.OpenWeb())
        {
            oWebsite.AllowUnsafeUpdates = true;
            SPList list = oWebsite.Lists["list_name"];
            EnableWorkflow(oWebsite, list, false);

            SPListItem listItem = list.GetItemById(listItemId); 
            //SPListItemColleciton listItemColl = list.GetItems();
            //foreach(SPListItem listItem in listItemColl) {}
            listItem["destinationFieldInternalName"] = listItem["sourceFieldInternalName"];
            listItem.SystemUpdate(false);
            EnableWorkflow(oWebsite, list, true);
            oWebsite.AllowUnsafeUpdates = false; 
        }
    }
}

private void EnableWorkflow(SPWeb web, SPList list, bool Enable)
{
    foreach (SPWorkflowAssociation Association in list.WorkflowAssociations)
    {
        Association.Enabled = Enable;
        list.Update();
        web.Update();
    }
}
</script>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.