How to foreach loop without warning

Hi, I want to know how to create a for each loop without showing warning as above.

In this action I'm trying to delete contacts using 'IsActive' attribute and 'Create or Update' server action. It works but there is a performance warning saying that you shouldn't include a server action in a loop which execute a server action multiple times.

I guess there are two solutions. First one is that I put the server action after the loop and save a list of contacts. The second one is that I put the loop within the server action. Although I don't know how in both ways.

The same kind of warning occurred when I tried to regex search and update(two server actions) in a client action.

I tried every course of reactive web app so I guess I missed something but I hope anyone helps me.

Thank you.


Hi Masafumi,

1) I would apply a ListFilter on the client side, with condition 'selected', and pass result of that listfilter to the server action

2) if the purpose of your server action is only to delete, you could even reduce the size of the input parameter list to just a list of CustomerContactId instead of a list of full CustomerContact record.

Dorine

Hi Masafumi YANO,

You are right, you have to create a server action and put the loop with server action to createOrUpdate inside of it and then call it in your client action. 

This way you will not have the warning because you are executing it on server side.

The same thing for the regex search and the update, you need to create a server action and put those server actions inside and call this new Server action with the two server actions on your Client Action.
Thank you.

So, the best thing to do is you run the for each inside of a server action. In this case, what you are going to do is pass as an input parameter the contact list that is going to be deleted and retrieve a message saying it was a success(if you want of course)!

You cannot have more than one server action inside of a client, if so, you need to pass everything to a server action.

In this case, you are executing more than once, but if it was just one time it was ok to have the server action on the client.

Kind regards,

Márcio

Hello,

that for_loop action you will execute in server wrapper action  and call that server action here

you are passing list to the forloop 

1)Create server action with xyzwrapper name, add one List Input parameter same that you are passing to the for loop.

in that server wrapper action implement same code


that server action call here before your refreshdata they will ask you Listinputparameter pass that as it is which your passing right now to for loop 

your using server action in client and in for loop so they will call every time from server to client in each loop to avoid this create whole the for loop logic in one server action .

may be this will helps you.

thanks and Regards,

Akshay Deshpande

Hi, Akshay, Márcio and Tiago

Thank you all for your help


It makes sense that I have to put all server actions in a server action.

Still, I don't know how to create a contact list which includes bulk information.

I made a custom server action called DeleteSelected. In the server action I created an input parameter called SelectedList giving a data type of Customer_Contact List. Then called it from the screen action giving the source List which includes bulk information. But in the If Condition in the server action I cannot find any bulk option in SelectedList.Current.


Do I do something wrong? If so, could you tell me what to do or even what to refer to to solve my problem again?

Thanks you


Hi Masafumi,

1) I would apply a ListFilter on the client side, with condition 'selected', and pass result of that listfilter to the server action

2) if the purpose of your server action is only to delete, you could even reduce the size of the input parameter list to just a list of CustomerContactId instead of a list of full CustomerContact record.

Dorine

Thanks Dorine,

You mean that you finish bulk actions on client side and just pass the filtered list to save it on server side?

Masafumi

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.