Extend Advanced Workflow configurable actions to trigger custom PHP code

Here it is a ready-to-use example on how to extend Advanced Workflows leveraging UI configurable custom PHP actions. It is based on the original example from SugarCON last year.

I've made it so that it is module aware (the developer can define module specific methods) and the method to call can be configured from the UI (only module specific methods will appear on the workflow).

The code is here: https://github.com/esimonetti/SugarAdvancedWorkflowCustomPHPMethods 

It will be extremely beneficial in situations where complex actions are required (eg: multiple lookups and records save at once), and UI action configuration/selection at the workflow level is required. The admin users with this type of customisation can have control on when and how the complex actions executed on the PHP side are triggered and have the flexibility to change the conditions that trigger them through the workflow UI.

The custom actions can be sent to the background and executed from the PHP side asynchronously, leveraging further our product's job queue to improve UI responsiveness for end users.

This should not be used as the silver bullet for everything, but it is a solid example to start with.

Feel free to have a look at the repository for more info!

Cheers

  • Hey Enrico,  

    Thanks for the post!  I am doing a more simplified custom advanced workflow on a vagrant localhost SugarCRM instance to test proof of concept. I have been following Robert Gonzalez's example: UnCon 2016 - Advanced Workflow Deep Dive Presentation .  Nothing seems to happen when I attempt to trigger the advanced workflow on an Account Record.  In the process management module it reports that my process definition is 'in progress' but never resolves.  Any thoughts on how I could debug or attempt to troubleshoot what I have done wrong?

    Thanks!

    Matt

  • Hi Brian,

    Not a problem!

    I would start by adding some logging on the PHP logic side, to see if that's triggered.

    I would also look at the php error logs, to see if there is any PHP error showing up as well. There might be a PHP syntax error?

    You have examples available here https://github.com/sugarcrm/uncon/tree/2017/advanced-workflow and here https://github.com/sugarcrm/uncon/tree/2016/awf_deep_dive 

    Cheers

    --

    Enrico Simonetti

    Sugar veteran (from 2007)

    www.naonis.tech


    Feel free to reach out for consulting regarding:

    • API Integration and Automation Services
    • Sugar Architecture
    • Sugar Performance Optimisation
    • Sugar Consulting, Best Practices and Technical Training
    • AWS and Sugar Technical Help
    • CTO-as-a-service
    • Solutions-as-a-service
    • and more!

    All active SugarCRM certifications

    Actively working remotely with customers based in APAC and in the United States

  • Brian Hearn,

    Are you using the code examples as-is without any changes, to start with? How did it go?

    --

    Enrico Simonetti

    Sugar veteran (from 2007)

    www.naonis.tech


    Feel free to reach out for consulting regarding:

    • API Integration and Automation Services
    • Sugar Architecture
    • Sugar Performance Optimisation
    • Sugar Consulting, Best Practices and Technical Training
    • AWS and Sugar Technical Help
    • CTO-as-a-service
    • Solutions-as-a-service
    • and more!

    All active SugarCRM certifications

    Actively working remotely with customers based in APAC and in the United States

  • Thanks Enrico,  

       I appreciate your help.  I have been working on some other stuff and I haven't had a chance to try out what you gave me but I will let you know.  

  • Enrico,  I added some loggin to the PHP side:

    $GLOBALS['log']->test('This is my test log message');

    This does not write to the log.  I used the code example as is without any changes.  Once again I have a localhost version 8.0 on SugarCRM on a Vagrant box.  

    Thanks for your time.

  • Brian Hearn,

    Do you mean: $GLOBALS['log']->fatal('here'); ?

    How about checking the apache error logs and php error logs (if separate), to see if you have any errors there?

    Do you see any api calls failure on the network tab?

    When you mention that you used the code example without any changes, which example are you referring to? The example on this thread, or which one of the other two that I have mentioned, so that I can attempt to see if it is a compatibility issue of the customisation?

    There are so many details that will need to be provided, to be able to get closer at debugging this.

    Some that come to mind are:

    1. Has the system's quick repair been executed correctly?
    2. Do you see the additional customised UI element on the workflows UI?
    3. Do you have a screenshot of your process design?
    4. Do they have a beginning and an end on the process?
    5. Do you have a screenshot of your "stuck in progress" processes, to see if we can understand anything from there, on where they get stuck? (follow Administration -> Process Management -> Preview Icon on the stuck process)
    6. What are the messages on the logs (PHP, Apache, sugarcrm.log, advanced workflows logs)?
    7. If you remove the custom action from the process UI, and use an out of the box action (eg: update a field on the module), does the process complete successfully or not?

    --

    Enrico Simonetti

    Sugar veteran (from 2007)

    www.naonis.tech


    Feel free to reach out for consulting regarding:

    • API Integration and Automation Services
    • Sugar Architecture
    • Sugar Performance Optimisation
    • Sugar Consulting, Best Practices and Technical Training
    • AWS and Sugar Technical Help
    • CTO-as-a-service
    • Solutions-as-a-service
    • and more!

    All active SugarCRM certifications

    Actively working remotely with customers based in APAC and in the United States

  • Enrico- 

    Thank you very much for your help.  As I walked through your checklist I was able to Robert Gonzalez's example: uncon/awf_deep_dive/src/custom at 2016 · sugarcrm/uncon · GitHub 

    I was able to get it to work. I had misspelled a php file.

    I am a SugarCRM newbie and I am wondering what would be the significance of creating a custom pmse object in the project manager library over creating a custom action by extending an already existing out of the box pmse object? 

    I have been reading over the documentation for Advanced workflow and the Process Manager in the documentation but was wondering what would be a good use case for creating a custom PMSE object.

    Two more questions if you have time:

    - What is the main difference of logic hooks vs advanced workflow besides the UI editor in the advanced workflow?

    - If I push a bunch of new records through the REST API to a module that has a Advanced Workflow or a logic hook registered on a new record event, will I run into blocking issues?

    Thanks!

  • Hi Brian Hearn,

    I am glad to hear you got it working, great!

    1) I don't think you create a custom PMSE object, you would always extend something that is already existing and it will be loaded by the getPMSEObject(). See more here: http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_8.0/Architecture/Advanced_Workflow/Exten… 

    The website lists what can be customised to date, depending on the specific need and requirement.

    2) Well, the UI editor first of all makes the actions configurable and flexible for the users. Say tomorrow the business changes a field requirement, or needs to change values of fields based on some conditions, it can be done through some clicks of mouse, instead of a software release.

    Aside from the UI, you have things like routings (that would take a considerable amount of time to implement through hooks), email notifications, time elapse (that can help with escalations and follow up), approval processes, setting conditionally of fields read only while the records is in certain state etc. I would suggest to try its functionalities out, there are also some examples on our website.

    All in all, going a little deeper, the workflows is executed either by an after save logic hook or if timer based, by a background queue, or by an action on the approval process dashlet.

    3) It depends. Usually you would not build a workflow that starts when every record of module X is saved. You would narrow down its start conditions based on the exact scenarios you want to cover (eg: when field one is A, field two is B, and field 3 changes from C to D). If you only have actions, yes those are synchronous, so I highly recommend to first define and design all the business processes required to meet the requirements, and then implement them in Sugar in the most optimal way, and eventually tweak them along the way.

    You have also the option of leveraging timers that can be added to help "push to the background" actions that are not required to be executed synchronously and/or by the current user.

    I did build the sample customisation listed at the beginning of this thread, to give some flexibility to the UI administrators, to select specific custom actions provided, and at the same time to help developers build custom actions that can be leveraged by the UI administrators to achieve quickly their goals.

    For example with the custom PHP method customisation example above, you could leverage it to build a "Synchronise with ERP" and "Synchronise with Marketing Automation" functionality. The functionality could asynchronously communicate with the ERP/Marketing Automation, by adding a job queue via PHP synchronously, and then executing the sync process later on. You could build multiple actions to do multiple things specific to your business, and then the UI Administrators can leverage those actions when appropriate to do so, and have the flexibility of changing the trigger points via a point and click UI. The same way you could build widgets to get the latest exchange rate, or go to google translate and translate your string, or geolocate an address, validate a phone number etc etc.

    Hope this makes sense

    Cheers

    --

    Enrico Simonetti

    Sugar veteran (from 2007)

    www.naonis.tech


    Feel free to reach out for consulting regarding:

    • API Integration and Automation Services
    • Sugar Architecture
    • Sugar Performance Optimisation
    • Sugar Consulting, Best Practices and Technical Training
    • AWS and Sugar Technical Help
    • CTO-as-a-service
    • Solutions-as-a-service
    • and more!

    All active SugarCRM certifications

    Actively working remotely with customers based in APAC and in the United States

  • Enrico- 

    Thank you very much.  Your whole write up makes perfect sense to me.  I appreciate all your insight and advice.  I think the last step in my journey is understanding the job queue and learn how to push custom php actions to the queue to execute asynchronously.  In your post you said:

    You have also the option of leveraging timers that can be added to help "push to the background" actions that are not required to be executed synchronously and/or by the current user

     

    In your example on github: GitHub - esimonetti/SugarAdvancedWorkflowCustomPHPMethods: SugarCRM's Advanced Workflow custom PHP actions  you specify in the readme that you are leveraging timers to push actions to the job queue.

    In my situation I would like to be able exactly that- to push my custom php activity in my Advanced Workflow to the background. I read through the job queue in the documentation:  http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_8.0/Architecture/Job_Queue/  and looked through the example of pushing a logic hook to the job queue (although I was not about to get it to work in a proof of concept). 

    My question is --

    1) where in your example of github are you pushing the custom action to the background?  Is that happening out of the box when you set up a wait event in the Advanced Workflow UI?  Or is there some logic that I am not recognizing in your code.

     

    Thanks in advance.

  • Hi Brian Hearn,

    No problem!

    Yes, you are correct, it is the Advanced Workflows timer that will make the system push the action in the background through the workflow engine (see screenshot at the bottom of the readme).

    A possible alternative is to use Advanced Workflows with a custom action that interacts directly with the job queue (and then it has the processing side of the queue to pick the action back up). In this case there would be no need of using timers, but then you would be forking your functionality even further from the actual process engine.

    Cheers

    --

    Enrico Simonetti

    Sugar veteran (from 2007)

    www.naonis.tech


    Feel free to reach out for consulting regarding:

    • API Integration and Automation Services
    • Sugar Architecture
    • Sugar Performance Optimisation
    • Sugar Consulting, Best Practices and Technical Training
    • AWS and Sugar Technical Help
    • CTO-as-a-service
    • Solutions-as-a-service
    • and more!

    All active SugarCRM certifications

    Actively working remotely with customers based in APAC and in the United States