locked
SharePoint workflow to Insert items with looping effect RRS feed

  • Question

  • Hello,

    I would like to achieve following actions. 

    • Let's assume there are two lists FirstList and SecondList.
    • FirstList contains a column called 'Number'  
    • When an item is inserted into FirstList a workflow starts. 
    • Now I would like the workflow to insert as many items with empty data in 'SecondList' list as the value  in column  'Number' is specified. 

    So basically I would like workflow to mimic something like this

    (User action)
    Insert Into FirstList(, ,Number, ,)

    (Workflow)
    While( i <= Number)
    Insert (, , ,) into SecondList 


    7929
    • Edited by PremShrestha Tuesday, November 15, 2011 10:43 PM
    Tuesday, November 15, 2011 10:18 PM

Answers

  • Hi Koolasice,

    I’m not clear about whether your workflow needs to be a Visual Studio Workflow or SharePoint Designer workflow. Here I have worked it out with SharePoint Designer workflow, you may have a test:

    1.       In the first list, create a point number column named PointNum, type of the column Number, default value:1, go to list settings->Advanced settings, set allow management of the content types to Yes, click the content type, in the list content type settings page, choose the column PointNum, set it to be hidden.

    2.       In the second list, create a point number column named num, type of the column Number.

    3.       Create a workflow on the first list: set start options: automatically start the workflow when an item is created, automatically start this workflow whenever an item is changed.
    conditions: if Number not equals 0
                             and PointNumber is less than or equal to first list:Number
    actions: create item in second list

    4.       Create a workflow on the second list: set start options: automatically start this workflow when an item is created
    actions: set Variable: workflownum to second list: num
                           then Calculate variable workflownum plus 1 (output to variable: workflownum)
                            then update item in first list (set the PointNumber to workflownum)

    Please have a try to check whether it works.

    Thanks,
    Qiao

    • Marked as answer by PremShrestha Friday, November 18, 2011 9:34 PM
    Friday, November 18, 2011 8:21 AM
    Moderator

All replies

  • Hi Koolasice,

    I’m not clear about whether your workflow needs to be a Visual Studio Workflow or SharePoint Designer workflow. Here I have worked it out with SharePoint Designer workflow, you may have a test:

    1.       In the first list, create a point number column named PointNum, type of the column Number, default value:1, go to list settings->Advanced settings, set allow management of the content types to Yes, click the content type, in the list content type settings page, choose the column PointNum, set it to be hidden.

    2.       In the second list, create a point number column named num, type of the column Number.

    3.       Create a workflow on the first list: set start options: automatically start the workflow when an item is created, automatically start this workflow whenever an item is changed.
    conditions: if Number not equals 0
                             and PointNumber is less than or equal to first list:Number
    actions: create item in second list

    4.       Create a workflow on the second list: set start options: automatically start this workflow when an item is created
    actions: set Variable: workflownum to second list: num
                           then Calculate variable workflownum plus 1 (output to variable: workflownum)
                            then update item in first list (set the PointNumber to workflownum)

    Please have a try to check whether it works.

    Thanks,
    Qiao

    • Marked as answer by PremShrestha Friday, November 18, 2011 9:34 PM
    Friday, November 18, 2011 8:21 AM
    Moderator
  • Hello Qiao,

    Thank you so much for answering my question. It helped a lot! 

    I already did it in little different way, but it's almost similar but your seems bit more efficient than mine. I created another list, just to track number of inserted items.

    Once again, thanks a lot for your response!  


    7929
    Friday, November 18, 2011 9:37 PM
  • Hi Qiao. I am trying to duplicate what you wrote here and am confused about one part.

    You wrote in step 3: "conditions: if Numbernot equals0
                             and PointNumberis less than or equal tofirst list:Number"

    Is the "Number" in the first half of the condition & "
    PointNumber" the same as the column"PointNum" in the first list? Or should there be another column in the first list called "Number"?

    Also, which column (or variable) is "tofirst list:Number"?

    then also you wrote in step 4:

    "then update item in first list (set the PointNumber to workflownum)"

    Again, is the "PointNumber" the same as the column"PointNum" in the first list?

    Friday, January 4, 2013 9:26 PM