I need help for the below scenario Data Manipulation

Hi All,

I have a scenario where i have list of string which is having 4 strings , like {“AU-0001”, “AU-0002”, “AU-0003”,“AU-0004”}.based on some condition i have to remove the elements from the list. If condition satisfies for all the list elements i have to delete that element from list. currently i am using invoke method with method as RemoveAt by passing the index. so whenever each element matches the condition it is getting removed and list is getting modified by reducing one count each time when condition matches. I am doing this in for each list items.When it comes to last element removal i am getting error like list index outside the bounds of array. Can someone let me know what approach i can follow for this?.

Thanks in advance.

Hi @shivarajvp555

Please take a look at this approach. You can create a list of strings, let’s say listA, which basically is a superset. Then upon iteration & conditions application, you can move the strings to another list, let’s say listB, which are supposed to be deleted. Now you have a listA which contains all the strings & listB which contains the strings that has to be deleted. Then you can use the following expression to basically exclude the listB from listA:

resultList = listA.Except(listB).ToList()

Hope this helps,
Best Regards.

Hi,

Can you share your workflow?
In general we can use RemoveAt method even if there is single item in the list like listvar.RemoveAt(0).

Regards,

Hi @shivarajvp555

Try with the following steps

  1. Use assign activity to Assign the List Values
myList (List<String>) = {"AU-0001", "AU-0002", "AU-0003", "AU-0004"}
  1. Use a For Each activity to iterate through each element in the list

  2. Add an If activity within the For Each loop to check the condition and remove elements

- For Each item in myList
  - If item.StartsWith("AU-0002")
    - Assign myList.Remove(item)

Regards
Gokul

I tried this it worked Thanks @Gokul001

1 Like

Thanks for your quick response @arjunshenoy I will try this approach as well. !!

1 Like