+ Start a Discussion
Bhavishya MoolyaBhavishya Moolya 

Visual Workflow parse through collection of records to see if values are same or not and then update a field based on the result

I want to compare the value in a collection - 

Example - "colorCollection" is a collection variable with values which are {Yellow, Yellow, Yellow, Yellow} then update the field "color" should be updated with the common color in that was in the collection, in this case, it should be Yellow
                 Now if the values in the collection are not the same, where "colorCollection" is {Blue, Green} the "color" field should be updated with the value mixed 

I tried to loop through the list but I am not able to compare the previous value with the next value. Any suggestions?
 
Best Answer chosen by Bhavishya Moolya
Gaurav HandooGaurav Handoo
Hi Bhavishya

One approach you can take here is below. However, this might be a lengthly approach to take up and include multiple loops and assumption that there are only limited number of colors.
  1. You would require as many Number variables as you have colors and Preferrably name them as "<Color>Counter" to ease the identification. E.g. If you have 5 colors, you would require 5 different boolean variables. with name YellowCounter, BlueCounter etc.
  2. You would need a generic counter to maintain the count of records in the collection.
  3. Loop one: Use this loop to get the Generic Counter to a number (this will depend on the number of records in your collection).
  4. Loop two: For each record getting processed in this loop, check the name of the color via decision box and based on the match, increase the ColorCounter by one. E.g. If first record is Yellow, then your YellowCounter goes to 1 and if the next record is Blue, then your BlueCounter goes to 1. Thus, by the end of the loop you will have count of times a particular color is getting repeated in the collection.
  5. Last you can add a check to compare the GenericCounter and Individual ColorCounters to see if you are matching any condition and then run corresponding update elements.

Hope this helps. Please mark as best answer if it does.

Cheers!!

Gaurav

All Answers

Gaurav HandooGaurav Handoo
Hi Bhavishya

One approach you can take here is below. However, this might be a lengthly approach to take up and include multiple loops and assumption that there are only limited number of colors.
  1. You would require as many Number variables as you have colors and Preferrably name them as "<Color>Counter" to ease the identification. E.g. If you have 5 colors, you would require 5 different boolean variables. with name YellowCounter, BlueCounter etc.
  2. You would need a generic counter to maintain the count of records in the collection.
  3. Loop one: Use this loop to get the Generic Counter to a number (this will depend on the number of records in your collection).
  4. Loop two: For each record getting processed in this loop, check the name of the color via decision box and based on the match, increase the ColorCounter by one. E.g. If first record is Yellow, then your YellowCounter goes to 1 and if the next record is Blue, then your BlueCounter goes to 1. Thus, by the end of the loop you will have count of times a particular color is getting repeated in the collection.
  5. Last you can add a check to compare the GenericCounter and Individual ColorCounters to see if you are matching any condition and then run corresponding update elements.

Hope this helps. Please mark as best answer if it does.

Cheers!!

Gaurav
This was selected as the best answer
Bhavishya MoolyaBhavishya Moolya
@Gaurav Handoo  Thanks so much, Gaurav! Yes, that works perfectly!! 
I really appreciate your detailed approach.