Unique field error
Collapse
X
-
Yes, you can. The info I gave you was just a guide, not the solution. You've to think about how you can make it work.
you cannot create a field without the type.
custom/Espo/Custom/Resources/metadata/entityDefs/<your-entity>.json
substitute <your-entity> with right value. If the vat field is in Lead then <your-entity> is Lead, so your file will be custom/Espo/Custom/Resources/metadata/entityDefs/Lead.json
Code:{ "fields": { "vat": { "type": "varchar", "maxLength": 255, "notNull": true, "trim": true, "required": true, "readOnly": false, "unique": true } } }
Comment
-
Thank you now it works, you have been very kind.
There is only one problem, if the field already exists from error 500, how can I display a personalized message as "VAT number already present"
Thanks againComment
-
espocrm/custom/Espo/Custom/Services/<Your-Entity>.php where <your-entity> is like Lead
PHP Code:namespace Espo\Custom\Services; use Espo\ORM\Entity; class Lead extends \Espo\Modules\Crm\Services\Lead { protected function getDuplicateWhereClause(Entity $entity, $data) { return array('vat' => $entity->get('vat')); } }
your extends <class> depends on what entity it is.
If you check espocrm/application/Espo/Modules/Crm/Services there will be a file called Lead.php. That's why I can extend it. If you don't know what to extend with, just check espocrm/application/Espo/Modules/Crm/Services path first to see if there is a file corresponding to <your-entity>, otherwise extend below metioned class
\Espo\Services\Record
which points to espocrm/application/Espo/Services/Record.php fileLast edited by theBuzzyCoder; 09-19-2019, 11:56 AM.Comment
-
Hello, thank you for having responded.
I tried how you wrote, but when I try to save a lead it gives me this error:
Errore 500: Class '\Espo\Custom\Services\Lead' does not exist.
[2019-09-26 18:42:14] Espo.ERROR: (500) Class '\Espo\Custom\Services\Lead' does not exist.; GET /api/v1/Lead?select=salutationName%2CfirstName%2ClastName% 2Cname%2Cstatus%2CaccountName%2CemailAddressIsOpte dOut%2CemailAddress%2CemailAddressData%2CassignedU serId%2CassignedUserName%2CcreatedAt&maxSize=100&o ffset=0&orderBy=createdAt&order=desc; line: 116, file: /var/www/html/espocrm/application/Espo/Core/ServiceFactory.php
Could you give me some suggestions?
Thank you very muchComment
-
Hi, this is the file
Thanks
PHP Code:namespace Espo\Custom\Services; use Espo\ORM\Entity; class Lead extends \Espo\Modules\Crm\Services\Lead { protected function getDuplicateWhereClause(Entity $entity, $data) { return array('partita_iva' => $entity->get('partita_iva')); } }
Comment
-
Comment
Comment