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

  • Enrico- 

    It's me again.  If I wanted to create a popup and some custom definitions for my custom action I would follow your example for the SearchableCombobox in 

    SugarAdvancedWorkflowCustomPHPMethods/activity.js at master · esimonetti/SugarAdvancedWorkflowCustomPHPMethods · GitHub -

    Here is your code I am referring to:

    var comboApi = new SearchableCombobox({
    label: translate('LBL_CUSTOM_LOGIC_TO_CALL'),
    name: 'act_service_method',
    placeholder: translate('LBL_PMSE_FORM_OPTION_SELECT'), etc....

    In my custom definition popup if I wanted to do something slightly different, like instead of an option set, create a textfield that the user types in.  Then that textfield would be passed to my pmse custom action.  How would I go about doing this?

    Would I create an instance of ComboboxField? 

    How would I go about implementing the functionality in this class? Any more info I could read to understand the different properties and how to use these objects that are located in the SugarCRM core pmse\activity.js file. 

    I appreciate it!

  • Brian Hearn,

    That's a good question. Currently I do not have a customisation example that implements something similar to what you are looking for. I will make sure to share it here, if it becomes available.

    Perhaps after a quick glance, it looks like what you might want to look further into, might be TextField?

    It does feel like you are looking at the right places though, that can lead you on how to implement what you are looking for.

     

    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

  • Hey Enrico Simonetti -

    Hope you are doing well!  I am seeing this issue with cron jobs and didn't know if you have any thoughts... Thanks!

    Every so often I am seeing this error in my SugarCRM logs when pushing a custom workflow to the Job queue.  Having a hard time tracking it down- not a lot of consistency.  It sometime happens when I push a bunch of jobs in the queue in a short period of time.  This error brings down the cron and I have to restart it to get it functional again.  Any help would be much appreciated!  Thanks!

    Fri Jul 13 19:47:24 2018 [4317][1][FATAL] Job fa289d96-86d3-11e8-8cd5-0800270fcb6c (Advanced Workflow Scheduled Job) failed in CRON run Fri Jul 13 19:47:24 2018 [4317][1][FATAL] An exception occurred while executing 'UPDATE job_queue SET name = ?, date_modified = ?, scheduler_id = ?, execute_time = ?, status = ?, resolution = ?, message = ?, target = ?, data = ?, requeue = ?, retry_count = ?, failure_count = ?, job_delay = ?, client = ?, percent_complete = ?, job_group = ?, module = ?, fallible = ?, rerun = ?, interface = ?, assigned_user_id = ? WHERE (id = ?) AND (deleted = ?)' with params ["Advanced Workflow Scheduled Job", "2018-07-13 19:36:02", "0285cb5c-86d0-11e8-9b0b-0800270fcb6c", "2018-07-13 19:36:02", "done", "failure", "Warning [2]: Creating default object from empty value in \/vagrant\/custom\/modules\/pmse_Inbox\/engine\/PMSEElements\/PMSEMyCustomAction.php on line 56

    Here is my code in PMSEMyCustomAction.php starting on line 56.  Nothing out of the ordinary.

    $bean->assigned_user_name = $variable1['userFullName'];
    $bean->assigned_user_id = $variable1['userId'];
    $bean->assigned_user_link->full_name = $variable1['userFullName'];
    $bean->assigned_user_link->id = $variable1['userId'];

    $bean->save();

  • Hi Brian Hearn,

    As pointed by the error, it would be good to understand what is wrong with line 56 on the custom code.

    I would highly recommend to have a look how to interact with beans (and related beans) from code, before proceeding further with customising the system in such complex scenarios like Advanced Workflows, as the code pasted does not look right. Link fields are used to load and/or add related records, not to store data within them directly.

    Some material that can help:

    Start maybe with simpler examples like a standalone custom api, and see if you can get the functionality working there first, by passing the input with a tool such as Postman. A great starting point would be Lauren Schaefer's tutorial here: Tutorial: Intro to the Sugar REST v10 API and all the ProfessorM scenarios as well.

    Hope it helps you move forward

    --

    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

  • Thank you.  

    "Link fields are used to load and/or add related records, not to store data within them directly."

    Was what I needed. 

    I will also look into your other recommendations.

    I appreciate it!

  • This has so many possibilities to overcome the limitations of the current process workflows. I can't wait to give it a try.  awesome work - thank you!

  • I want multiple custom actions in Workflow.

    In activity.js, I have tried the code as follows, but it doesn't work. Anyone tried such scenario of creating multiple custom action in workflow.

    AdamActivity.prototype.customContextMenuActions = function() {
    return [{
      name: 'CREATE_OPPORTUNITY',
      text: 'Create Opportunity'
    }, {
      name: 'CREATE_MEETING',
      text: 'Create Meeting'
    }]
    };

    AdamActivity.prototype.customGetAction = function(type, w) {
    switch (type) {
    case 'CREATE_OPPORTUNITY':
    var actionText = 'Create Opportunity (Action)';
    var actionCSS = 'adam-menu-icon-configure';
    var disabled = false;
    return {
    actionText: actionText,
    actionCSS: actionCSS,
    disabled: disabled
    };
    case 'CREATE_MEETING':
    var actionText = 'Create Meeting (Action)';
    var actionCSS = 'adam-menu-icon-configure';
    var disabled = false;
    return {
    actionText: actionText,
    actionCSS: actionCSS,
    disabled: disabled
    }
    }
    };

    /**
    * Needed to define the modal that pops up with a form
    * @param {string} type The action type
    * @return {object} Definition needed for a modal
    */
    AdamActivity.prototype.customGetWindowDef = function(type) {
    switch(type) {
    case 'CREATE_OPPORTUNITY':
    var wWidth = 500;
    var wHeight = 140;
    var wTitle = 'Create Opportunity';
    return {wWidth: wWidth, wHeight: wHeight, wTitle: wTitle};
    case 'CREATE_MEETING':
    var wWidth = 500;
    var wHeight = 140;
    var wTitle = 'Create Opportunity';
    return {wWidth: wWidth, wHeight: wHeight, wTitle: wTitle};
    }
    }

    In Workflow Action menu, I got only one action at a time. I want 2 or more action over there. Anyone tried this scenario?

  • Hi Kishor Mali,

    In your case for "create meeting" or "create opportunity" wouldn't you be able to just leverage the create record functionality present in the system?

    In any event, the example provided has one action, but it can have N configurable paths (through the PHP file methods). You would have that option as well.

    I am not sure currently of your specific problem though.

    Hope it helps you move forward

    --

    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

  • Hi Enrico Simonetti,

    Create record functionality is not working in my case, because I have to assign to much customize data while creating opportunity and meeting.

    Opportunity case

    1) Account : I need to attached the account which is already attached to Contact which is present in my current meeting from where I am creating opportunity.

    2) One Meeting to many Opportunities : I created this custom relationship.

    Same complex case is also with Meeting module. That's why I need multiple custom action in workflow.