QuickSearch - choose/show Contact dependent of Accounts field

Hi,

i have a module which has one-to-many relationship to accounts and contacts.
Now if I choose an Account, I want only the dependent contacts of this Account to be shown in the Quick Search of Contacts field.

Is this possible to implement? Can someone guide me?
Thank you

What is “the Quick search of Contacts field”? Can you perhaps share a screenshot? Also, please say what your version of SuiteCRM is.

Maybe what you’re looking for is this?

http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_6.5/Module_Framework/Metadata/Examples/Adding_QuickSearch_to_a_custom_field/

Thank you for your answer!
I am using the most current 7.10.7 SuiteCRM Version.

Well I have added a one-to-many relationship to Cases from Contacts,
so you can now choose a contact inside the case.

But as described above, the contact field is not dependent on the accounts field.

Hope this clarfies the issue.
The link you posted I already read, but its not clear enough for me sadly…and I am not sure if it there is my issue described.

I’m playing around but I haven’t found a way to make this work yet.

Any way, you probably don’t need a Relationship for this, you could simply go in Studio / Cases and add a relate field linking to Contacts. This uses a simpler UI and probably achieves what you want. It also adds quick search by default (we just need to find out where to configure that query…).

There is something you can do with the “initial_filter” property in editviewdefs.php, you can Google it.

But it affects only the pop-up for Selection, not the Quick search.

I think changing the quick search is much harder, involves a bunch of changes including JS.

Hey and thank you so much for getting into a solution for this issue.

Initial Filter: yes I already implemented that one. But the quick search is of course still missing.

About the relationship definition - I guess it does not matter if I take a relationship or a related field,
in both cases the quick search query has to be customized so it takes the account field into consideration.

But as you said, it seems difficult - hopefully someone can enlighten us to get this done! I am not in fear to edit all the quicksearch js files to get this running!

This link looked promising but I couldn’t figure out where to do the changes:

https://community.sugarcrm.com/thread/28339

Maybe you can discover…

I got some help from a friend telling me where this Edit view JS is supposed to be…

	
    'DetailView' => array(
        'templateMeta' => array(
            'form' => array(
                'buttons' => array(
                    'EDIT',
                    'DUPLICATE',
                    'DELETE',
                    'FIND_DUPLICATES'
                )
            ),
            'maxColumns' => '2',
            'widths' => array(
                array(
                    'label' => '10',
                    'field' => '30'
                ),
                array(
                    'label' => '10',
                    'field' => '30'
                )
            ),
            'includes' => array(
                array(
                    'file' => 'modules/<module>/js/<your-file-name>.js'
                )
            ),
...

This can be added both to DetailViewDefs and EditViewDefs
You just add the"includes" section and include as many files as you want, from any path.

I’m afraid I don’t have time to try it myself, but I believe with this information you should be able to try it. Good luck.

Thank you for your help!
I am nowhere a full developer, but even if you link this customJS file,
there must be a place where you call the function customSqs()
from the customJS file…

only because you write it into Edit/DetailViewDefs - i am not thinking that it will call the function customSqs?

As said, I am no real developer, only trying to customize our CRM - and its really hard for me to debug the whole system and its functionalities…
really crossing my fingers someone come over to this thread with the same issue, and getting it done with a solution which works…

You are correct. Like you, I am approaching this issue with a clearly insufficient understanding of everything that’s going on, and og how these files are actually used.

Maybe your best chance is to post on that SugarCRM forum thread and hope the developer who posted that customSqs comes back and clarifies things…

@pgr you are correct on the way to add the file to a specific module view.

Now if you want to make your file available our javascript function anywhere, we need to modify file custom/include/SugarFields/Fields//EditView.tpl
and add similar to this:

  <script type="text/javascript" src='{sugar_getjspath file="custom/include/SugarFields/Fields/<your_field_type>/js_file_name.js"}'>
 </script>

Now. How we call the function on the actual field? IF you have been able to achieve it please let me know how.

Thanks,

AlxGr

Dont know If your looking for the same thing as me…

I’ve setup an initial_filter on a relative field wich work great, but the auto complete ignore that fitler, so my filter is useless if the user dont open the pop up, and directly type in the field.

Trying to apply that filter to the quick search. I’ve followed a lot of topic, tryed the “Adding QuickSearch to a Custom Field” on the sugar dev guid PDF (Page 594)

excatly like this old topic :

https://suitecrm.com/suitecrm/forum/suitecrm-7-0-discussion/7443-related-field-auto-complete

I will continue my research, if I found a solution, I’ll post it here.

This resource might help you:

https://web.archive.org/web/20171122132629/http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_6.5/Module_Framework/Metadata/Examples/Adding_QuickSearch_to_a_custom_field/

2 Likes

Its the page I was mentioning in the PDF ahah.

Anyway, I made it guys !

Here is the code :

  var formName='EditView_'; // form name
  var fieldName= 'parent_name'; // field name to override SQS
  var sqsId = formName + fieldName;
  sqs_objects[sqsId]['conditions'] = [{
  "name": "name",
  "op": "like_custom",
  // "begin": "%",
  "end": "%",
  "value": ""
  }, {
  "name": "account_type", // name of field to apply filter
  "op": "like_custom", // Operator Equal ne marcher pas! Il fallait like_custom
  "begin": "%",
  "end": "%",
  "value": "Fournisseur" // Value to compare
  }];
  sqs_objects[sqsId]['group'] = "and";

The main error on the link before was “op”: “equal”. I think in sugar CRM 6.5 (the one SuiteCRM use) we dont have that operator. I remplaced it by like_custom

2 Likes

cool, i will maybe try this, where did you add this code?

In a custom JS file that you include in your viewdefs.

It personnally completly work for me. Only displaying my account with type “Fournisseur”.

Quick update : The code dont work when u use the “createview”, when u create a new account for exemple. Trying to fix this !

Find out why it dont work, cause of the ajax in the URL :

/index.php?action=ajaxui#ajaxUILoc=index.php%3Fmodule%3DOpportunities%26action%3DEditView%26return_module%3DOpportunities%26return_action%3DDetailView

/index.php?module=Opportunities&action=EditView&return_module=Opportunities&return_action=DetailView

On the first URL the SQS filter dont work, on the second one it work …

If any one know how I can fix this !

Is this reported somewhere on GitHub? I think we have enough information to be close to a fix, but I would ask you to please open an issue if you don’t find any one already there.

I’ve dont opened an issue on github but I find how to correct my bug :

Delete my code from my custom.js file

C/C it in my view.edit.php like this :

		$ScriptValidation = <<<EOT
<script type="text/javascript" language="JavaScript">

	//Fait a partir de : https://community.sugarcrm.com/thread/28339
	//custom QuickSearch. ca ma aidez un peut : https://web.archive.org/web/20171122132629/http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_6.5/Module_Framework/Metadata/Examples/Adding_QuickSearch_to_a_custom_field/
	
	//Cooperative Parent -> Enfant
	var formName='EditView_'; // form name
	var fieldName= 'accounts_accounts_1_name'; // field name to override SQS
	var sqsId = formName + fieldName;
	sqs_objects[sqsId]['conditions'] = [{
	"name": "name",
	"op": "like_custom",
	// "begin": "%",
	"end": "%",
	"value": ""
	}, {
	"name": "account_type", // name of field to apply filter
	"op": "like_custom", // Operator Equal ne marcher pas! Il fallait like_custom
	"begin": "%",
	"end": "%",
	"value": "Cooperative" // Value to compare
	}];
	sqs_objects[sqsId]['group'] = "and";
  
	
	//Compte -> Cooperative
	var formName='EditView_'; // form name
	var fieldName= 'accounts_accounts_2_name'; // field name to override SQS
	var sqsId = formName + fieldName;
	sqs_objects[sqsId]['conditions'] = [{
	"name": "name",
	"op": "like_custom",
	// "begin": "%",
	"end": "%",
	"value": ""
	}, {
	"name": "account_type", // name of field to apply filter
	"op": "like_custom", // Operator Equal ne marcher pas! Il fallait like_custom
	"begin": "%",
	"end": "%",
	"value": "Cooperative" // Value to compare
	}];
	sqs_objects[sqsId]['group'] = "and";	
</script>
EOT;

// Echo du code
        echo $ScriptValidation;

Now everything work ! I can create with ajax :smiley: I think that was cause my custom JS file was fired too late after the ajax call or something… in view.edit.php everything work great, for now !

2 Likes