Forums

Custom Code execution after a Connection Action

bcouvin 12 Dec, 2015
Hi All,

I really need your help, since 3 days trying to solve my issue.

Here is my case. Sorry for the long text below, but the use case is really simple. This may help for the ChronoEngine community:

(1)- In Chronoform, I have access to the form which describes the organization of the project team. The goal of this form is to obtain the project_id and the list of project team members. Those informations are in stored in 1 record. One column for the project_id and one column for the list of project team members. As I do not know the number of the team member (array), this list is stored as a string which contains the list of user_id. I use "implode" and "explode" to store and to extract the user_id from this list. The primary key is project_id. Those informations are stored in table that I called it "Table (1)".

(2)- In Chronoconnectivity, I have a list of projects with the same information structure. One column is project_id, one column is the list of project team members (user_id). I used a Connection Action to save information in the "Table (1)" and "Table (3)" Please see below for the definition of "Table (3)".

(3)- "Table (3)" is managed outside of Chronoform and Chronoconnectivity. This table stored the information of assignment of project team member in the projects.
One column is user_id, one column is the project_id, another column is the role which is played by the user_id in the project_id. The primary key is id for the "Table (3)".
[list]- project_id has many user_id (one project has many project Team member)
- user_id has many project_id (one user is assigned to several projects).
[/list]

Remark: on PrImary Key. You can imagine that the "Table (2)" that I did not described here is the user_id and his skill he can play in the project. The primary key in "Table (2)" is user_id.

So here is my problem, and my use case:
In a existing project in the chronoconnectivity project listing, I want to modify the list of my project team members.
[list]- Initial project_id_1, my list of project team member is user_id_1, user_id_2, user_id_3. Those information are stored in the "Table (1)" and "Table (3)".
- New Assignment, project_id_1, my new list of project team member is user_id_2, user_id_4.
[/list]


When the project is new, I use chronoform to write informations into 2 tables:
[list]- dbsave action in chronoform for the "Table (1)"
- Custom code to write into "Table (3)", as this one does not have Chronoform to support this table[/list]

When the project has to be updated in the case of new assignment, and this project is accessed from the project listing (ccv5), I have the connection action to save the "Table (1)". This one works fine. But the custom code for writing new information is not executed after the Connection Action. This code (in php) is dedicated to the "Table (3)", as used and described above, has to delete the row where the user_id_1 and user_id_3 were assigned in project_id_1, and to add the user_id_4 in the project_id_1.
This code must be after Connection Action, because I need to know the project_id when the new project is created from the listing.


Do you have some solution to execute this php code after the Connection Action Save because in CFv5 does not execute Custom code avec the Connection Action? and where I can integrate this code in CCv5.


Sorry again for my long description, hope that you clearly understand what I was trying to do since 3 days.
Thanks in advance for your advice.

Bertrand
GreyHead 12 Dec, 2015
Answer
1 Likes
Hi Bertrand,

My first reaction is that there are possibly some problems with your table design that may be making the work more complicated.

I would have Table 1 with just the information about the project but not the list of team members

In Table 2 I think you only have the detail about the users.

Your Table 3 already has the information about which Members are assigned to each project so you don't need to repeat that in Table 1 (If you do then there are immediately problems in ensuring that the data is consistent between the two tables.)

I am not clear why the Project ID isn't available in the form On Submit event? Is this because it is a new project? In that case how are you linking to it from CC?

The simplest solution may be to use a standard link from CC to open the form, add the Custom Code + DB Saves as needed, then redirect back to the listing without using the CC action.

Bob
bcouvin 13 Dec, 2015
Hello bob,

Thank for your advice.

"The simplest solution may be to use a standard link from CC to open the form, add the Custom Code + DB Saves as needed, then redirect back to the listing without using the CC action."
This is the solution. It was obvious and I did not think to replace Connection Action Save by DB Save and Custom Code to write into Table 2.
When the project is new, I only get the project_id after a DB Save, because DBSave creates a new row with its id (primary id key).

Bertrand
GreyHead 13 Dec, 2015
Hi Bertrand,

Glad to hear that works.

Generally I think that the CC action is only useful when you open a form to edit or view an existing record. To create a new one it's more practical to add a [New] link in the Header or Footer of the listing.

Bob
bcouvin 13 Dec, 2015
Bob,

Do you know why the "NEW" button in CCv5 opens the form in the current window and the same one in another browser tab? I got 2 same form.

Bertrand
GreyHead 13 Dec, 2015
Hi Bertrand,

Sorry, no, I've not seen that before.

Bob
This topic is locked and no more replies can be posted.