Create a custom folder in Windows for each opportunity that is created

Good morning.
As a company, we are using the Crm to store opportunities and make quotes. The previous system (excel) allowed us to create automatically (macro) a custom folder in windows for each opportunity and in which we store quotation data from any source.
Is there a way to do the same in suitecrm and create a new empty folder with the opportunity name where it is created in suite?

Thank you!

Hi MARTIGNONI,
welcome to SuiteCRM!

Since Suite is being executed on a webserver, you usually can’t create folders on your clients file system. Of course you could create (sub)folders on the webserver itself or on a network drive using mkdir() within a logic hook.

Hi
Thank you very much, I will try to create them on a network drive and with a queue logic hook.
The best would be to create a folder when a new opportunity (and only then, not when it is modified) is created. Any coding suggestion is welcome!

Many Thanks

Hey,
I’ve made a small example.

  1. First of all, I created a folder “accounts” in my installation folder
  2. I’ve added this code to my Logic_Hooks.php-file (custom/Extension/modules/Accounts/Ext/LogicHooks/Logic_Hooks.php):
$hook_array['before_save'][] = Array(
    850,
    'createFolder',
    'custom/modules/Accounts/FolderGenerator.php',
    'FolderGenerator',
    'createFolder');
  1. I’ve added FolderGenerator.php in the given location with
<?php
class FolderGenerator{
    function createFolder($bean, $event, $arguments){
        //new bean?
        if ($bean->fetched_row == false) {
            $path = "accounts/".$bean->name;
            //does folder exist?
            if(!is_dir($path)){
                //create folder
                mkdir($path);
            }
        }
    }
}

Now, for each new account a subfolder is being created in accounts/.

Please note: this is very basic example that I created very quickly. I’m sure the community will have some concerns (like: is the account name always a proper subfolder name?).
Further, you should take care to not overwrite already existing hooks (instead, push the hook into the existing array).

In the end everything I showed here was copied and modified from the linked article, hope it helps!

1 Like

Hello, I am wondering if this has worked for anyone. I am looking to create a folder on the webserver for every new project created in SuiteCRM. Thanks!

this is an old one :slight_smile: I’m not sure if I was testing the code back then, but usually I copy and paste from my IDE, so it should be working in general. In your case, you have to alter the structure above a bit (different logic-hook file).

E: yep, tested it locally just now with 7.12.6. Works in general, I’ve added a short if-else to verify that the first subfolder becomes created automatically too:

<?php
class FolderGenerator{
    function createFolder($bean, $event, $arguments){
        //does first subfolder .../myProjectFiles/ exist?
        if(!is_dir('myProjectFiles')){
            mkdir('myProjectFiles');
        }
        //new bean?
        if ($bean->fetched_row == false) {
            $path = "myProjectFiles/".$bean->name;
            //does folder ../myProjectFiles/myProjectName exist?
            if(!is_dir($path)){
                //create folder
                $result = mkdir($path);
            }
        }
    }
}

Every new project creates now a new subfolder in mySuiteInstallationPath/myProjectFiles/Projectname.

If you’re struggling with the code above, pls verify by debugging/logging that the method createFolder() is actually being executed. This is the first important step.

1 Like

Thanks for your help! I got this working.

How would I be able to add 3 sub folders within the project folder created (e.g., folder1, folder2, folder3)?

E: ah, I understand:

class FolderGenerator{
    function createFolder($bean, $event, $arguments){
        //does first subfolder .../myProjectFiles/ exist?
        if(!is_dir('myProjectFiles')){
            mkdir('myProjectFiles');
        }
        //new bean?
        if ($bean->fetched_row == false) {
            $path = "myProjectFiles/".$bean->name;
            //does folder ../myProjectFiles/myProjectName exist?
            if(!is_dir($path)){
                //create folder
                $result = mkdir($path);
				mkdir($path . "/folder1");
				mkdir($path . "/folder2");
				mkdir($path . "/folder3");
            }
        }
    }
}
1 Like

Worked perfectly! Do you know if I can also print from a PDF template automatically during this process?

It should be possible, but I don’t have examples at hand. But I guess you should find something here in the community about pdf processing.

1 Like