Filter results on related field into edit (popup and quicksearch)

Hello,
In my suitecrm I need to do this.

In module A, I have a relate field with module B and I would like filter results (both on popup, and in quicksearch when user digit on field and appear results like a select)

My condition is that moduleB.migration_status_c <> ‘BLOCKS_FOR_MIGRATION’

alternatively, how can I intercept using javascript that the value of the related field change? (I’m able to intercept only when selected using quicksearch, and click deleted button, but not if I select record from popup)

I’m not able to find a solution that works.

Can someone help me?

Thank you in advice

I don’t know the answer, but if you search these forums for “sqs” you might find interesting posts. I think those are related to what you’re asking.

1 Like

https://community.suitecrm.com/search?q=sqs

If I understand correctly, this is pretty easy.

Example:

For example. In quotes, you may want to add a relate field to “requested by” which is a contact. With the quote, you already have the quote related to the Account so you just want a subset of the contacts to show that are related to the account. You use the initial_filter for this.

In: /custom/module//metadata/editviewdefs.php

Just add to the add to the array:

			  'initial_filter' => '&account_name_advanced="+this.form.{$fields.billing_account.name}.value+"',

Here’s an example with mulitple conditions:

initial_filter' => '&name_advanced="+this.form.{$fields.field1}.value+" AND field2_advanced="+this.form.{$fields.field2}.value+"',

Substitute field1 and field2 with the desired field names from your current module.

This takes care of the Popup, I can’t remember and it’s not clear from my notes if it also takes care of the SQS. (I think it does though).

thank you for your reply.
It works, but just for quicksearch.

this is the change that I added to editviewdefs.php

'displayParams' => 
				array (
					'initial_filter' => '&t_migration_status_c<>\"BLOCKS_FOR_MIGRATION\"',
				),	

If I try to open popup (with arrow button) I receive a message error:
image

Your syntax is not correct you need the _advanced to make it apply to the popup.

Here’s an example for leads status=new.

'initial_filter' => '&status_advanced=New&account_name_advanced="+this.form.account_name.value+"',

Try this:

'initial_filter' => '&migration_status_c_advanced=!BLOCKS_FOR_MIGRATION',


@bf.ts90 if this works out ffor you can you confirm if it also works for the SQS in the field and I’ll update mynotes on it accordingly. (I think you already said it did, just want to confirm)

Sorry for the delay in my answer but I comeback to work with my suitecrm now.
unfortunately your solution doesn’t work,

filter does not works in quick search and in popup too. :frowning:

I tried these:


'displayParams' => 
				array (
					'initial_filter' => '&t_migration_status_c_advanced!=\"BLOCKS_FOR_MIGRATION\"',
				),	
			),
'displayParams' => 
				array (
					'initial_filter' => '&t_migration_status_c_advanced=!\"BLOCKS_FOR_MIGRATION\"',
				),	
			),
'displayParams' => 
				array (
					'initial_filter' => '&t_migration_status_c_advanced!=BLOCKS_FOR_MIGRATION',
				),	
			),
'displayParams' => 
				array (
					'initial_filter' => '&t_migration_status_c_advanced=!BLOCKS_FOR_MIGRATION',
				),	
			),
'displayParams' => 
				array (
					'initial_filter' => '&t_migration_status_c_advanced<>BLOCKS_FOR_MIGRATION',
				),	
			),

Another problem is that, when in popup I made a search, the initial filters were reset and I lost the filter that I need

I have it working on a few intstallations of version 7 with code I provided. Keep playing with the syntax. If you’re on version 8, not sure if this will work for you.

did you try this:

'initial_filter' => '&t_migration_status_c_advanced!="BLOCKS_FOR_MIGRATION"',

I receive this error when try open popup

You can not use double quotes twice.

Write same as mentioned by pstevens.

image

this is my code :sweat_smile:

You’re right I can’t get it to work either with more than one condition.

This works:

'displayParams' => array(
    'initial_filter' => '&account_name_advanced="+encodeURIComponent(this.form.name.value)+"',
    'field_to_name_array' => array(
        'name' => 'key_contact_c',      // Contact name field
        'id' => 'key_contact_id_c',    // Contact ID field
    ),
),

I can filter by contacts of the account but if I try to add a second filter, I just can’t get the syntax right. If I edit the URL of the popup I can add the condition but I can’t seem to get the syntax right in the initial filter. Also, I can only get equal to a value to work, “not equal” I can’t get to work any way I try.

Sorry, you’re going to have to try to write JS if you can’t find the right syntax for the second condition.

(I have a second field non_active_c which I’m filter by equal to 0, I can’t get it “not equal” to 1)

/index.php?module=Contacts&action=Popup&query=true&account_name_advanced=24%2F7%20Couriers&mode=single&create=true&field_to_name=name&non_active_c_advanced=0

I can also get this to work, just not both at the same time:

'displayParams' => array(
    'initial_filter' => '&non_active_c_advanced=1',
    'field_to_name_array' => array(
        'name' => 'key_contact_c',      // Contact name field
        'id' => 'key_contact_id_c',    // Contact ID field
    ),
),

After doing some more research, its not possible to pass a “not equal to” to the URL. The != only returns a true or false , not an array of values that do not equal the specified value.

I can also get this URL to work in the popup, but can’t seem to get multiple conditions to work in the initial filter:

/index.php?module=Contacts&action=Popup&query=true&account_name_advanced=24%2F7%20Couriers&non_active_c_advanced=1

Ok I got this to work with multiple parameters. So I’m selecting based on that the contact is related to the account and that non-active = 0

'displayParams' => array(
        'initial_filter' => '&non_active_c_advanced=0&account_name_advanced="+encodeURIComponent(this.form.name.value)+"',

    'field_to_name_array' => array(
        'name' => 'key_contact_c',      // Contact name field
        'id' => 'key_contact_id_c',    // Contact ID field
    ),
),

However I still don’t think “not equal” is posible. If you can select based on “equal” to something you can get it.

Thanks for your explanation.
I imagine that my problem is because it is not possible to use the condition ‘field not equal to value.’

In my case, the field is a dropdown menu, so I need to retrieve all records where the field t_migration_status_c is equal to a list of values (all dropdown menu values except BLOCKS_FOR_MIGRATION).

I don’t need to dynamically retrieve all values from the dropdown menu; it’s fine to hardcode them in the code. In this case, how should the condition string be structured?

Thank you in advice

B

Youll need to test if an “or” logic works. You can research how to construct that on Google. I think its as the operator.