locked
Using Skip or SkipWhile in a Workflow RRS feed

  • Question

  • How do you use Skip or SkipWhile in a workflow (wf4)?  I suspect you use InvokeMethod, TargetObject = your collection, Methodname  = Skip/SkipWhile, but from there, Im lost.

    FYI, I am currently using a Native Activity strictly through the designer.

    Thanks

    Monday, November 28, 2011 5:51 PM

Answers

  • Hi,

    I think a While activity nested in a ForEach activity apply to your scenario.

    ForEach<Cat>

    Foreach Cat in Categories

    Body

          Sequence

          variable={i}

                While

                Codition  i<Cat.objects.count && (Cat.objects[i] isn't hited)

                Body  

                      Assign  i=i+1

                Sequence           

                       surcharge;

                       Assign i=0

    • Edited by Franconia Friday, December 2, 2011 3:33 AM
    • Marked as answer by LeoTang Sunday, December 4, 2011 3:30 PM
    Friday, December 2, 2011 3:27 AM

All replies

  • You could put an If activity inside a ForEach activity- is that what you're looking for?
    Tuesday, November 29, 2011 9:38 PM
  • Is that the C# LINQ style Skip or SkipWhile?
    Assuming you want to do it on an IEnumerable as using the extension method, you could treat the extension method as a static method and do InvokeMethod on type 'Enumerable', passing the IEnumerable as the first argument.
    Tim

    Wednesday, November 30, 2011 4:06 AM
  • Yes, I am using C#.  I am actually attempting to skip over "duplicate" objects in a collection.  Say I had a collection of items with a surcharge.  They fall into categories: 5 may be in Cat A, 0 in Cat B, 7 in Cat C, 4 in Cat D, etc.  BUT, I want to apply the surcharge ONLY ONCE for each category with an item in it.  In other words, I hit an item in Cat A, apply the surcharge, then skip the others in Cat A, and move on to the next category.

    Could easily code in C#, but wondering if I can do this in the Workflow Designer, no code behind.

    Wednesday, November 30, 2011 12:52 PM
  • Hi,

    I think a While activity nested in a ForEach activity apply to your scenario.

    ForEach<Cat>

    Foreach Cat in Categories

    Body

          Sequence

          variable={i}

                While

                Codition  i<Cat.objects.count && (Cat.objects[i] isn't hited)

                Body  

                      Assign  i=i+1

                Sequence           

                       surcharge;

                       Assign i=0

    • Edited by Franconia Friday, December 2, 2011 3:33 AM
    • Marked as answer by LeoTang Sunday, December 4, 2011 3:30 PM
    Friday, December 2, 2011 3:27 AM