How can I execute a formula (in this case ext/email/send) with a custom button in detail view. If not possible, could anybody provide the necessary action to achieve this. Thanks in advance.
Announcement
Collapse
No announcement yet.
Execute a formula with custom button
Collapse
X
-
My solution has always been to create a hidden boolean field (default is "false"), then create a button that changes the field's boolean state to "true", the "true" state triggers the formula process at the end of which add a command to change the field's boolean back to "false".
Example:
PHP Code:ifThen(entity\isAttributeChanged('hiddenBooleanField')
&& hiddenBooleanField == true,
$sendEmailButton = record\create(
'Email',
'from', 'email@address.mail',
'to', emailAddress,
'status', 'Draft',
'isHtml', true,
'parentId', id,
'parentType', 'ParentType',
);
ext\email\applyTemplate($sendEmailButton, 'templateIdNumber');
ext\email\send($sendEmailButton);
hiddenBooleanField = false;
);
Last edited by heligonaut; 03-18-2024, 02:19 PM.
Comment
-
Comment
-
-
Thanks @eymen, I followed everything I could find about buttons and actions. I understand every single example, but I don`t get, how an action is named, when it is different from putting a link to the button or open a Google search (as in the examples). Every action has another code/commands, that I merely don`t get.
I guess my javascript skills are simply too poor (if existent at all)
-
-
Simple example
PHP Code:actionMyActionForButton: function (data, e) {
this.view.model.set('hiddenBooleanField', true);
this.view.model.save();
Espo.Ui.notify("Action OK!", 'success', 5000);
}
Comment
-
heligonaut, thank you very much again. I guess I do not have enough skills in javascript.....
I will try with this one, thanks again.
-
-
I copied the code exactly from the espoCRM doc but I do not even get the button to appear. I always get the error "JSON syntax error". Here is my code for the button:
PHP Code:"menu": {
"detail": {
"buttons": [
"__APPEND__",
{
"label": "Fragebogen absenden",
"name": "fragebogenAbsendenButton",
"action": "fragebogenAbsendenAction",
"style": "default",
"acl": "edit",
"aclScope": "Software",
"data": {
"handler": "custom:fragebogen-absenden-action-handler"
},
"initFunction": "initManageFragebogenAbsendenAction"
}
]
}
},
I do not see anything wrong. Anybody does?
Comment
-
As the error message says, JSON syntax is invalid. There should not be the trailing comma, and your entire code should be wrapped into { ... }. https://docs.espocrm.com/development...p-right-corner
Comment
-
For few days I am trying (with the above help) to implement this in my custom entity, but do not get it to work. I acnnot see, if the button would be displayed, as the detal view does not open.
As I do not get it to work, I want to ask for pointing me to the direction, where I did something wrong.
So I will post all files involved.
My custom entity is named "Software". The action I want to execute is "fragebogen absenden" (fragebogen means questionnaire), which will be the attachment to send by mail.
The file custom/Espo/Custom/metadata/Resources/clientDefs/Software.json is already present, as there is some of the configuration of fields etc..
I want to display a button, which should execute a formula to send an email with an attachment.
My files:
custom/Espo/Custom/metadata/Resources/clientDefs/Software.json: I added this code
Code:"menu": { "detail": { "buttons": [ { "label": "Fragebogen absenden", "name": "fragebogenAbsendenButton", "action": "fragebogenAbsenden", "style": "default", "acl": "edit", "aclScope": "Software", "data": { "handler": "custom:fragebogen-absenden-action" }, "initFunction": "fragebogenAbsenden" } ] } }
Code:Espo.define('custom:views/software/fragebogen-absenden-action', 'views/detail', function (Dep) { return Dep.extend({ setup: function() { Dep.prototype.setup.call(this); this.addMenuItem('buttons', { name: 'fragebogenAbsenden', label: 'Fragebogen absenden', style: 'primary', acl: 'edit', action: 'fragebogenAbsenden' }, true); }, actionFragebogenAbsenden: function (data, e) { this.view.model.set('hiddenBooleanField', true); this.view.model.save(); Espo.Ui.notify("Fragebogen gesendet", 'success', 5000); } });
ifThen(entity\isAttributeChanged('hiddenBooleanFie ld')
&& hiddenBooleanField == true,
$sendEmailButton = record\create(
'Email',
'from', 'email@address.mail',
'to', emailAddress,
'status', 'Draft',
'isHtml', true,
'parentId', id,
'parentType', 'ParentType',
);
ext\email\applyTemplate($sendEmailButton, 'templateIdNumber');
ext\email\send($sendEmailButton);
hiddenBooleanField = false;
);
Thank you in advance.
- Likes 1
Comment
Comment