Invoking a server action from another

Hi,
I have a server action, let’s call it SA1 that is invoked by a form1 in page1.php. SA1 does a lot of calculations and creates a bunch of records in different tables.
SA1 is rather complex (at least for me :grinning: )

I have another server action, let’s call it SA2, which is invoked by forms in page2.php. SA2 is also long and complex, and I’d rather not make it longer by repeating all the steps currently in SA1. Thus, I would like to invoke SA1 from within SA2, and pass to SA1 the equivalent to all the POST variables that form1 passes to SA1.

Is it possible to do that? If so, is there any guidance on how to do it? Alternatively, is there any way to copy the contents of SA1 and paste them into SA2? Doing the work manually is time consuming and error prone.

Many thanks,

Alex

Hi @aschoijett!

I don’t have a direct answer to your question, but I have what may be a neat solution.

I use a lot of stored procedures in MySQL to handle the situation you describe… Then you can put the repetitive data creation tasks in the procedures and just call them with a single custom query from your different server actions.

Good luck!
Best wishes,
Antony.

1 Like

Hey Alex,

If Antony’s very valid suggestion doesn’t work for you, every server action can be called with the api action step.

For example, if you have a server connect called fetch_trans that is in a folder called trans you would call:

https://{{$_SERVER['HTTP_HOST']}}/dmxConnect/api/trans/fetchTrans.php

The $_SERVER portion is just inserting at runtime the server it is running on. /dmxConnect/api/ is static, and the rest is just the folder path and file with php extension.

You can call a POST or GET depending on what you want to do, and pass any information in query or input data depending on what you choose. Keep in mind that SESSION variables will not be available as a new session is triggered by the api call – just pass any values needed using the input or query params.

Here is what one of mine looks like:

2 Likes

I just want to say thank you. It took me a while until the API call started working (several weird issues) but now works very well.
Thanks for the pointer!

Alex

1 Like

@George while this API may work, isn’t it an idea to make a visual picker for this in the server actions? Then you can easily select another server action to run directly without having to use:

https://{{$_SERVER[‘HTTP_HOST’]}}/dmxConnect/api/trans/file.php

1 Like

Well yes maybe just like with the new flows we can have a server action step to just call another server action @patrick

2 Likes

I need to do lots of these… am just working on it now the API way, but could leave it a week or two if this proposed feature were to be released shortly… :thinking:

Here is a use case where this feature might be useful…

Also, another situation where this might be useful is when dealing with login/registration (esp in oauth2 based ones) - if email address is current user -> call login-server-action, if not -> call registration-server-action…

This is a nice hack, but instead of routing the input data/header etc to another server-action api, would be good if there was a way to “invoke” and pass on “control” to another server-action!