AnsweredAssumed Answered

Custom Activity Workflow

Question asked by Brian Hearn on May 18, 2018
Latest reply on May 18, 2018 by Francesca Shiekh

Hi, 

 

My name is Matt.  I'm trying to get my head around SugarCRM development.

 

I am having issues configuring a custom activity workflow for proof of concept purposes.

 

I have followed all of the steps in this documentation:

 

UnCon 2016 - Advanced Workflow Deep Dive Presentation 

 

These are my steps

1) Created a custom Advanced Workflow class and saved it as this location:

- custom/modules/pmse_Project/clients/base/api/wrappers/CustomPMSEProjectWrapper.php.

- Here is the code:

<?php

require_once 'modules/pmse_Project/clients/base/api/wrappers/PMSEProjectWrapper.php';

class CustomPMSEProjectWrapper extends PMSEProjectWrapper
{


}

 

2) Added javascript to add action to the designer at this location:

- custom\include\javascript\pmse\capitalize_action.js

- Here is the code:

AdamActivity.prototype.customContextMenuActions = function() {
return [{
name: 'CAPITALIZE_NAME',
text: 'Capitalize Record Name'
}]
};

AdamActivity.prototype.customGetAction = function(type, w) {
switch (type) {
case 'CAPITALIZE_NAME':
var actionText = 'Capitalize the Record Name (Action)';
var actionCSS = 'adam-menu-icon-configure';
var disabled = false;
return {
actionText: actionText,
actionCSS: actionCSS,
disabled: disabled
}
}
};

 

3) Added the custom javascript into the js bundles at this location:

- custom\Extension\application\Ext\JSGroupings\capitalize_action.php

- Here is the code:

<?php

foreach ($js_groupings as $key => $groupings)
{
foreach ($groupings as $file => $target)
{
//if the target grouping is found
if ($target == 'include/javascript/pmse.designer.min.js')
{
//append the custom JavaScript file
$js_groupings[$key]['custom/include/javascript/pmse/capitalize_action.js'] = $target;
}
break;
}
}

 

4) Added the class that runs on the server at this location:

- custom\modules\pmse_Inbox\engine\PMSEElements\CustomPMSEElement.php

Here is the code:

<?php

require_once 'modules/pmse_Inbox/engine/PMSEElements/PMSEElement.php';


class CustomPMSECapitalizeName extends PMSEElement implements PMSERunnable
{

public function run($flowData, $bean=null, $externalAction = '', $arguments = array())
{
$this->capitalizeName($bean);
$flowAction = $externalAction === 'RESUME_EXECUTION' ? 'UPDATE' : 'CREATE';
return $this->prepareResponse($flowData, 'ROUTE', $flowAction);
}

public function capitalizeName(SugarBean $bean)
{
if($bean instanceof SugarBean) {
foreach ($bean->field_defs as $name => $defs){
if($this->isNameField($defs)){
$fields = $this->getNameFields($defs);
foreach($fields as $field){
$bean->$field = strtoupper($bean->$field);
}
}
}
$bean->save();
}
}

protected function getNameFields($defs)
{
if (isset($defs['db_concat_fields'])){
return $defs['db_concat_fields'];
}

if(isset($defs['name'])){
return array($defs['name']);
}

return array();

}

protected function isNameField($defs)
{

if(isset($defs['type'])&& $defs['type'] === 'name'){
return true;
}

if(isset($defs['type']) && $defs['type'] === 'fullname'){
return true;
}
return false;

}
}

 

5) Ran quick repair and rebuild.

 

6) Set up a new advanced workflow.

- Added a start event on Leads with update records

- Added my custom Capitalize Record Name action

 

7) Tested my work by updated a Lead record and nothing happens.

 

Any thoughts on what I am doing wrong?

 

Many thanks!

 

Matt

Outcomes