you should add this to the Opportunity and not Dealer.js
It is your mistake you didn't share the correct info. i didn't know that Dealer has many opportunities.
show in listing only active entries
Collapse
X
-
Hey,
Screenshot 1: Dealer Module > Bottom Panel > Creating Opportunity > Selecting Contact for Opportunity.
Screenshot 2: Selecting Opportunity from the Bottom Panel.
Screenshot 3: Selecting Contact from the Bottom Panel.
Am i missing something?3 Photos -
Here is the code below, copy and paste and it should work fine
PHP Code:define('custom:handlers/select-related/same-dealer-many', ['handlers/select-related'], Dep => { return class extends Dep { /** * @param {module:model.Class} model * @return {Promise<module:handlers/select-related~filters>} */ getFilters(model) { let advanced = {}; let dealerId = null; let dealerName = null; if (model.get('dealerId')) { dealerId = model.get('dealerId'); dealerName = model.get('dealerName'); } if (!dealerId && model.get('parentType') === 'Dealer' && model.get('parentId')) { dealerId = model.get('parentId'); dealerName = model.get('parentName'); } if (dealerId) { let nameHash = {}; nameHash[dealerId] = dealerName; advanced.dealers = { field: 'dealers', type: 'linkedWith', value: [dealerId], data: {nameHash: nameHash}, }; } return Promise.resolve({ advanced: advanced, }); } } });
Leave a comment:
-
Hey rabii,
The handler json i changed to AMD with the help pf chatgpt.
/************************************************** **********************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************** **********************/
import SelectRelatedHandler from 'handlers/select-related';
class SameDealerManySelectRelatedHandler extends SelectRelatedHandler {
/**
* @param {module:model} model
* @return {Promise<module:handlers/select-related~filters>}
*/
getFilters(model) {
const advanced = {};
let dealerId = null;
let dealerName = null;
if (model.get('dealerId')) {
dealerId = model.get('dealerId');
dealerName = model.get('dealerName');
}
if (!dealerId && model.get('parentType') === 'Dealer' && model.get('parentId')) {
dealerId = model.get('parentId');
dealerName = model.get('parentName');
}
if (dealerId) {
const nameHash = {};
nameHash[dealerId] = dealerName;
advanced.dealers = {
field: 'dealers',
type: 'linkedWith',
value: [dealerId],
data: {nameHash: nameHash},
};
}
return Promise.resolve({
advanced: advanced,
});
}
}
// noinspection JSUnusedGlobalSymbols
export default SameDealerManySelectRelatedHandler;
Still nothing changed?Leave a comment:
-
The issues is clear you are using ES6 in your custom handler which will not work. Use AMD instead. -
NOTE: Now, Creating and View List a Contact from bottom panel of Dealer is happening, But Selecting is not working. Please refer the attached screen shot.1 PhotoLeave a comment:
-
Hey,
I'm not sure where I'm going wrong; this issue has been pending for quite a while. As per your instructions, I created the src, handlers, and select-related directories and added the js file inside them, but it’s still not working.
Could there be an issue with the relationship between the Dealer and Contact modules? Is there something specific in the handler script I should check, like a field name or other configuration?
Could you review the handler script to see if there’s anything I need to verify or adjust?
Also, I hope you're aware of my process. From the Dealer module, in the bottom panel, I am creating an Opportunity. While creating this Opportunity, I want to select a related Dealer contact person for this Opportunity.
Last edited by Ashif Malayil; 11-04-2024, 10:16 AM.Leave a comment:
-
in order for espocrm to get your custom code to work, this should be done via installable extension or via custom directories. keep it simple don't use modules directory as the system need to scan it as if an installable directory.
Keep it simple move your custom handler to client/custom/src/handlers/select-related (Create those folders if they don't exist) -
Hey,
This is the path where i created the custom handler.
client/src/handlers/select-related# ls
same-account.js same-account-many.js same-dealer-many.js
In this path (client/custom/handlers/select-related), I have a "modules" directory after custom.
client/custom# ls
modules
Then, in this path:
client/custom/modules/advanced/src/handlers# i don't have select-related directory.
However, I got confused with the paths?Leave a comment:
-
Hey,
I assume the custom handler is located under custom folder in your client folder. then you need to fix it as below
PHP Code:"contacts": { "selectHandler": "custom:handlers/select-related/same-dealer-many" },
I assume the custom handler is located under client/custom/handlers/select-related (then you need fix as above) it should be custom:handlers/select-related/same-dealer-many
Just remove layout and selectPrimaryFilterName as you don't need themLeave a comment:
-
Hi rabii,
I have customised my own select handler:-
client/src/handlers/select-related/same-dealer-many.js
/************************************************** **********************
* This file is part of EspoCRM.
*
* EspoCRM – Open Source CRM application.
* Copyright (C) 2014-2024 Yurii Kuznietsov, Taras Machyshyn, Oleksii Avramenko
* Website: https://www.espocrm.com
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* The interactive user interfaces in modified source and object code versions
* of this program must display Appropriate Legal Notices, as required under
* Section 5 of the GNU Affero General Public License version 3.
*
* In accordance with Section 7(b) of the GNU Affero General Public License version 3,
* these Appropriate Legal Notices must retain the display of the "EspoCRM" word.
************************************************** **********************/
import SelectRelatedHandler from 'handlers/select-related';
class SameDealerManySelectRelatedHandler extends SelectRelatedHandler {
/**
* @param {module:model} model
* @return {Promise<module:handlers/select-related~filters>}
*/
getFilters(model) {
const advanced = {};
let dealerId = null;
let dealerName = null;
if (model.get('dealerId')) {
dealerId = model.get('dealerId');
dealerName = model.get('dealerName');
}
if (!dealerId && model.get('parentType') === 'Dealer' && model.get('parentId')) {
dealerId = model.get('parentId');
dealerName = model.get('parentName');
}
if (dealerId) {
const nameHash = {};
nameHash[dealerId] = dealerName;
advanced.dealers = {
field: 'dealers',
type: 'linkedWith',
value: [dealerId],
data: {nameHash: nameHash},
};
}
return Promise.resolve({
advanced: advanced,
});
}
}
// noinspection JSUnusedGlobalSymbols
export default SameDealerManySelectRelatedHandler;
Then, i added the file inside custom/Espo/Custom/Resources/metadata/clientDefs/Dealer.js
"contacts": {
"layout": null,
"selectPrimaryFilterName": null,
"selectHandler": "handlers/select-related/same-dealer-many"
},
Clear cache and Rebuild done from CLI and Administration. Still the filter is not coming for Dealer entity while choosing Contacts.Last edited by Ashif Malayil; 11-04-2024, 06:33 AM.Leave a comment:
-
Hey Ashif Malayil
Because in your custom entity Dealer you need to provide a custom filter for the contacts field Or just use an already existing selecthandler that will do the same job (luckly espocrm provides few out of the box). Here is what you need to do go to your custom/Espo/Custom/Resources/metadata/clientDefs/Dealer.js and just add this line to the contacts on relationship as below
PHP Code:"relationshipPanels": { "contacts": { "selectHandler": "handlers/select-related/same-account-many" // This is the line you need to add ad the end of your contacts } }
Please remove my comment above and only addCode:"selectHandler": "handlers/select-related/same-account-many"
NB: It is important that the account link on the Dealer is called account and accountId otherwise the above wouldn't work and you need to customise your own select handler.
Once done, clear_cache and then rebuild the system and it should workLast edited by rabii; 10-31-2024, 02:27 PM.Leave a comment:
-
rabii Attached are the screenshots for reference.- Screenshot 1: In the "Account" entity, I’m creating an "Opportunity" from the bottom panel. When mapping a related Contact to the "Opportunity", I see only the related "Contacts" for the "Account" in the default filter, which is working as expected.
- Screenshot 2: In the "Dealer" entity (a custom entity of type "Company"), I don’t get the same behaviour. Instead of showing only the related "Contacts" for this "Dealer", it shows all "Contact" records.
I would like to replicate the same behaviour for the "Dealer" entity, so that only related "Contacts" appear when mapping. Could you guide me on how to achieve this? Should I use a report filter or a select handler? I have raised this issue previously as well, but I am still unable to resolve it.2 PhotosLeave a comment:
-
1 - Create a file under Espo\Custom\Classes\Select\Account\PrimaryFilters\ Active (Active.php) (Remember to change the name of the field to the correct name you have in your instance
PHP Code:<?php namespace Espo\Custom\Classes\Select\Account\PrimaryFilters; use Espo\Core\Select\Primary\Filter; use Espo\ORM\Query\SelectBuilder; class Active implements Filter { public function apply(SelectBuilder $queryBuilder): void { $queryBuilder->where([ 'isActive' => true, ]); } }
2 - Create a file Account.json under (Espo\Custom\Resources\metadata\selectDefs\Account .json)
PHP Code:{ "primaryFilterClassNameMap": { "active": "Espo\\Custom\\Classes\\Select\\Account\\PrimaryFilters\\Active" } }
3 - Create or Add this to Account.json (if already exist) under (Espo\Custom\Resources\metadata\clientDefs\Account .json)
PHP Code:{ "filterList": [ "__APPEND__", "active", { "name": "active", "style": "success" } ], "defaultFilterData": { "primary": "active" } }
Hope this helps.Leave a comment:
-
Simple way (you need to display the Active field in Administration > Entity Manager > Account > Layouts > Search Filters)
Complex way (Report filter with EspoCRM file editing): https://forum.espocrm.com/forum/feat...2689#post92689Leave a comment:
Leave a comment: