How can i add filter on related field . like I have user type related field on which I have want to show only user related user with some role . how is this possible ?
i tried through this
bt not working
How can i add filter on related field . like I have user type related field on which I have want to show only user related user with some role . how is this possible ?
i tried through this
bt not working
This is not possible OOTB, you need to create a custom endpoint which returns such filtered list and render its result inside a dropdown field.
Hi neeraj verma,
I am not so sure about you want to get. But I dare to suggest you that check the relationships or you create a relationship with the target module.
The module where you have the user type and the users module and may be whit the rol, but I think you can´t create a relationships with roles. This is because the edit user view shows you the related rol or the assigned rol to the user.
I hope it be useful for you.
Regards.
i try to explain again .. above is my user related lookup on sugar , I wnt to search only users with specific roles .. how can I do it
You can extend the vardef file to add a "filter_definition". For example, in the field custom/Extension/modules/<module>/Ext/Vardefs/sugarfield_<field_name>.php, you can add something like:
$dictionary['<module>']['fields']['<field_name>']['filter_definition'] = [
[
'aclroles.name' => '<role_name>'
]
];
Then do a quick repair and rebuild - and by default, it will auto-filter based on the definition above - but this doesn't enforce the filter, users are free to remove the filter and set any record they want, but the default search will filter by the role you specify.
Hey Neeranja P,
Could this also work for restricting contacts for accounts in related modules?
Overview:
When an Account is selected and the user goes to choose the Contact, I want to restrict the Contacts available to only those on the Account....but the the detail here is that account is a dynamic values (not like the '<role name'>)..
Link to Simirar case
Example: ( Getting only the contacts of the account selected <TestAccount>)
I've tried like you mention above but im not sure what to consider as my <module>(cases or account) and sugarfield (in custom/Extension/modules/<module>/Ext/Vardefs/sugarfield_<field_name>.php)...is not throwing any errors nor the queries expected.
Hi Karen Escritorio,
Yes this will work for any relate field and dynamic fields as well. It works just like regular filters.
The field where your module is present is the <module>. Lets say this is "Cases" module.
The actual field name that you want to restrict should be <field_name>.. Lets say this is the "contact" field.
So the file that you'll have to create is:
custom/Extension/modules/Cases/Ext/Vardefs/sugarfield_contact.php
Now, all dynamic parameters can be substituted with "#", so in this case, the filter definition could look like:
$dictionary['Case']['fields']['contact']['filter_definition'] = [
[
'account_id' => '#account_id'
]
];
What we're trying to do is to filter Contacts by account_id - and the dynamic parameter to use is the #account_id of the Case module.
Well, I guess you can do an onlyread field, as same as you do with the relationship of the role field you can do with readonly.
If I am sure you must do
$dictionary['<module>']['fields']['<field_name>']['filter_definition']['readonly'] = true;
And that converts the field in a simply label, not editable by the user.
See if this helps