开发者

SharePoint 2010 "foreach"

I have 2 SharePoint lists, and I have to copy all items from List1 to List2.

On List1 there is a boolean field (defaults to 'no'), a text field and an associated WorkFlow which triggers on modifications.

The WokFlow simplified:

  1. Copy current item to List2
  2. Set my boolen field to 'yes'
  3. Search for an item with boolen field 'no', set its text field to 'copy'

I start the process by modifing an item in List1, then it will copy itself to List2, modifies an another item, and so on... until there is any item with a boolen field set to 'no'.

This works perfectly for 10 items, but then it fails. Ite开发者_Go百科m 10 modified item 11's text field to 'copy', but item 11's WorkFlow does not started. I've tried it serval times, and always stopped after 10 copies.

I've Googled and MSDN'd. The best solution I've found is to pause for 1 minute in the WorkFlow. But I have thousands of items...

Has anyone any advice? I even cant find any limit in the SharePoint 2010 server that defaults to 10.

Thank You!


You are triggering a hardcoded resource throttle in SharePoint 2010 due to the speed on the workflow. It's there to prevent the system from becoming unresponsive during workflow operations. Code in an application page or timer job will get around this limit but it's not recommended to have a greedy operation that cause the system to become unresponsive to users.


You can do CAML batch methods.

somethig like this:

    void UpdateList()
    {
        StringBuilder methodBuilder = new StringBuilder();
        string batch = string.Empty;
        string newValue="mmmm";
        string updateColumn = "SampleColumn";


        try
        {
            string batchFormat =    "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
                                    "<ows:Batch OnError=\"Continue\">{0}</ows:Batch>";
            string methodFormat = "<Method ID='{0}' >" +
                                    "<SetList>{1}</SetList>" +
                                    "<SetVar Name='Cmd'>Save</SetVar>" +
                                    "<SetVar Name='ID'>{2}</SetVar>" +
                                    "<SetVar Name='urn:schemas-microsoft-com:office:office#{3}'>{4}</SetVar>" +
                                    "</Method>";

            using (SPSite siteCol = new SPSite("SampleSite"))
            {
                using (SPWeb web = siteCol.OpenWeb())
                {

                    // Get the list containing the items to update
                    SPList list = web.Lists["SampleList"];
                    string listGuid = list.ID.ToString();
                    SPListItemCollection allItems = list.GetItems();

                    // Build the CAML update commands.
                    for (int i = 0; i < allItems.Count; i++)
                    {
                        int itemID = allItems[i].ID;
                        methodBuilder.AppendFormat(methodFormat, itemID, listGuid, itemID, updatedColumn, newValue);
                    }
                    web.AllowUnsafeUpdates = true;

                    // Generate the CAML
                    batch = string.Format(batchFormat, methodBuilder.ToString());

                    // Process the batch 
                    string batchReturn = web.ProcessBatchData(batch);

                }
                //done
            }

        }
        catch (Exception ex)
        {
    //show the error
        }

    }

You can create batch methods for create , delete and update items on lists and document libraries.

Refs:

http://msdn.microsoft.com/en-us/library/office/ms437562%28v=office.15%29.aspx

http://msdn.microsoft.com/en-us/library/office/ms459050(v=office.15).aspx


if you want to change workflow concurrent execution limits ....

For check limits:

 Get-SPFarmConfig | Select WorkflowPostponeThreshold 

For change

 Set-SPFarmConfig -WorkflowPostponeThreshold 50 

Timer service process items ( workflows continuations) on batch sizes

 Get-SPFarmConfig | Select WorkflowBatchSize 

 Set-SPFarmConfig -WorkflowBatchSize 150 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜