Filter account listview by code

hey everyone, here is what I want to achieve :

I have 3 types of account : A, B and C

I have made a custom menu with 3 link : A,B and C

I used this small trick to pass the filter, in the URL :

/index.php?action=ajaxui#ajaxUILoc=index.php%3Fmodule%3DAccounts%26searchFormTab%3Dbasic_search%26query%3Dtrue%26account_type%3DTHE-ACCOUNT-TYPE-HERE

So I made 3 link with this method wich work great but I discovered a bug with this method :
The collumn customisation is not saved. If a user add or delete collumn from the list view with the button (the Columns Filter Link) , and click on one of the 3 account type it will reset the collumn settings.

I have tried this method too : http://www.urdhva-tech.com/blogs/extending-list-view-query-in-sugarcrm

But in my case I have 3 conditions in 3 link different, so its not really for me.

I have tried pretty much everything I found on internet, so my question is :
How I can add a filter by PHP (or Javascript ?) code if the user type on my custom menu link ? If he click on A need to put account_type = A and the same for the 2 others.

Thanks in advance !

I have an idea with a great forum post I just discovered:

https://www.ciconet.it/en/soluzioni/182-predefined-searches-in-sugarcrm-ce-65-or-suitecrm.php

You can create custom filters for every user with the searches you want.

Thanks for the reply but this is to create savedsearch (=filter), it not explain how to force the user to use the filter

What I need is :
If URL = this then put this filter

Trying with a link in yours : https://www.sugaroutfitters.com/blog/default-searches-on-list-views

This can be a starting point …

UPDATE :

$squery= new StoreQuery();
//specify query and save
$squery->query=array('account_type'=>'Provider', 'module'=>'Accounts','searchFormTab'=>'basic_search','query'=>'true','action'=>'index');
$squery->SaveQuery('Accounts'); 

Work if I apply it in the preDisplay() function, will test the fix today to see if it work correctly in every situation…

UPDATE 2 :
Unfortunately it does the same issue : dont save the custom collumn of the user…

1 Like

Hi holdusback,
You can also do one thing, for different filters you can create custom list view action where you can call custom listview templates .This way you can see different set of columns in list view according to filter .

1 Like

Thanks for the reply ! Do you have an idea how to do that ? Maybe another topic of the forum ?

Hi,
You need to define custom actions in controller,and then make custom views in views folder by using custom tpl files.

1 Like

I finaly took the time to test your solution.

I have 3 menu link that filter account different way.
The issue is that my user reported that when they click on one of the link, it reset the collumn customisation, so If they added collumn to the list view, they have to re-add them everytime wich is terrible for the workflow.

Your solution look like to pre-made a preset for the listview, but In my case that my user that choose wich collumn they want to see or not.

Im pretty sure that I have to do something with ajax. Still trying to fix this !