Create Project from Opportunity fails when adding a Project Template

I am trying to add a Project Template to a workflow when an Opportunity is set to a specific stage.

I can get the project to create but as soon as I tell it to set the Project Template to an existing Project Template the system crashes on a save. Keep in mind though that the project is created even though it crashes but has no tasks. There apache error logs shows:

[Tue May 30 13:50:31.764298 2023] [php7:error] [pid 1399] [client 192.168.110.180:50678] PHP Fatal error: Uncaught Error: Call to a member function add() on null in /var/www/suitecrm-dev/SuiteCRM-7.12.7/branch/modules/Project/Project.php:543
Stack trace:
#0 /var/www/suitecrm-dev/SuiteCRM-7.12.7/branch/modules/AOW_Actions/actions/actionCreateRecord.php(406): Project->save(true)
#1 /var/www/suitecrm-dev/SuiteCRM-7.12.7/branch/modules/AOW_Actions/actions/actionCreateRecord.php(169): actionCreateRecord->set_record(Object(Project), Object(Opportunity), Array)
#2 /var/www/suitecrm-dev/SuiteCRM-7.12.7/branch/modules/AOW_WorkFlow/AOW_WorkFlow.php(965): actionCreateRecord->run_action(Object(Opportunity), Array, true)
#3 /var/www/suitecrm-dev/SuiteCRM-7.12.7/branch/modules/AOW_WorkFlow/AOW_WorkFlow.php(229): AOW_WorkFlow->run_actions(Object(Opportunity), true)
#4 /var/www/suitecrm-dev/SuiteCRM-7.12.7/branch/include/utils/LogicHook.php(260): AOW_WorkFlow->run_bean_flows(Object(Opportunity), ‘after_save’, ‘’)
#5 /var/www/suitecrm-dev/SuiteCRM-7.12.7/branch/include/utils/LogicHook.php(201): LogicHook->process_hooks(Array, 'af in /var/www/suitecrm-dev/SuiteCRM-7.12.7/branch/modules/Project/Project.php on line 543, referer: https://suitecrm7-dev.kwikom.com/index.php

I have found other messages that speak to this but I did not find any solutions.

This is what my Actions look like:

This is what the code looks like in /modules/Project/Project.php

            //copy all resources from template to project
            $template->load_relationship('am_projecttemplates_users_1');
            $template_users = $template->get_linked_beans('am_projecttemplates_users_1', 'User');

            $template->load_relationship('am_projecttemplates_contacts_1');
            $template_contacts = $template->get_linked_beans('am_projecttemplates_contacts_1', 'Contact');


            foreach ($template_users as $user) {
                $focus->project_users_1->add($user->id);
            }

            foreach ($template_contacts as $contact) {
                $focus->project_contacts_1->add($contact->id);
            }


According to the error, $template_users results in a null value. The Project Manager is set to Administrator and all but one of the steps is set to Administrator except the last one is set to a user.
Here is the view of the Project Templates View page.

I am not sure how to fix this. Any ideas?

Tony

Duplicated this issue on the demo site.

Have a look at the database, in the case of a Project normally created through the UI. Look for relationships to the Users table, not just assigned users and “project manager”.

→ https://github.com/search?q=repo%3Asalesagility%2FSuiteCRM%20am_projecttemplates_users&type=code

@pgr,

I really don’t know what your asking me check into. For some reason I have a mental block and have a hard time understanding how SuiteCRM uses the relationships. I need to better understand this.

Can you elaborate a bit?

I looked at the gitHub link you sent and it looks to me that all of them already exist in my code. Version 7.12.7.

Tony

Try in two steps. You’re not going to be able to create the project template at same time as the project because the required relationships won’t be established (I think?) until after the project is saved.

Thanks @pstevens,

Two workflows do work as you suggested. The second workflow is for Projects and uses the run Only In The Schedular and on New records.

Additionally, you have to manually add all of the Tasks as a separate Create Record action and include each field in the project_task table.

The only problem I have is that the “Assigned To” field name assigned_user_id; does not show in the gantt chart nor am I able to change it. I think this has to do with the project resources. I don’t know how to set these when the project is created. When editing the project after it is created there are no users to select from.

If I can set the available resources then this process will work. Its takes time to set it up but would be easily managed if needed.

Tony

I think what you want to do in the workflow is “add a relationship” in projects to “assigned user” and or “users:resources”

I am not sure I did this right. It now shows the Administrator in the dropdown but none of the other users that are in the project template.

Maybe I do not understand.

This was added to the first workflow that modifies the project.

image

You did select some users to add to the project in users:resources relationship? (not sure from your screenshot)

Not sure you can do this when you create the project, because the project won’t be created yet for you to add the relationships to. Usually relationships to you have to add after the record you want it to related to is created and saved.

Ok,
Well I did put the relationship on the wrong workflow. So I removed it from #2 and added it to the first workflow. This time I did select staff to be part of the resources.

The assignments were correct and the drop down for the Assigned To shows up with the resources.

So my Opportunity Workflow #1 - Create Project is like this:

image

This certainly is a lot to do to get the project created verses using the code. However, this allows others to modify it without digging into the code and I don’t have to worry about looking in the database for id’s which is what I have to do in the code version.