Grouping logic on lookup filters

  • 1
  • Idea
  • Updated 3 years ago
  • Not Planned
Grouping logic on model conditions are awesome. It would be nice if we could apply grouping logic on lookup filters as well.
Photo of Gyan

Gyan

  • 1,400 Points 1k badge 2x thumb

Posted 4 years ago

  • 1
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
The reason we have not further invested in filter specifics in lookup filters is that you can use a model as the source for your lookup options.  (See Option Source in the Search Properties).  This means you can use all the model features to make your lookup list as specific as you need. 
Photo of Gyan

Gyan

  • 1,400 Points 1k badge 2x thumb
Thanks Rob for your reply. Model approach works for me in almost all cases except one, ownerId. 
If I want to assign a record (custom object record) to only group or only user or only selected users  or selected groups, on what object and how should I create a model?
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Owner ID looks up to the User Object.  So make a model on User and filter as you wish.  Use a subquery condition to filter down to groups. 
Photo of Gyan

Gyan

  • 1,400 Points 1k badge 2x thumb
Hi Rob, for custom object records, model on User does not seem to work. I already tried it. For example, if I want to get only Active users and all the groups on the owner field (rendered as picklist) how would I apply lookup filters or model. Neither model on User nor model on Group seem to work if I go with model approach.
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,006 Points 20k badge 2x thumb
Owner is a polymorphic relationship.  So when you edit the field, you first choose which target object you are looking up.  (In this case Users or Groups).  When you put a lookup filter directly on one of these objects,  and the field selected for the fitler is not on the second object,  the filter is thrown out when there is not a field name that matches the filters field. 

So if you filter users by "Active"  - when you select groups,  it should throw out the user filter and show you all available groups.    This means that you don't really need group logic on your filter.  Nor do you need to use a model source for your lookup filter. 

The reason the model source did not work, was that the lookup filter was looking for a particular Id.  Since the Id field is available on both the User and Group objects,  the condition was being applied to both - and no group records were being returned.  

There is one wrinkle.  The filter on "user = active" is not correctly creating the condition.  It does not detect that the active field is a boolean and provide a checkbox for the value.  You have to go to the XML and adjust the lookup field condition slightly.  Make the eclosevalueinquotes value = "false"

See below: 



Hope that helps. 
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
I've got this need to have grouping logic. My use case is that I'd like to look Tasks related to one of three object records that are related.

I've created an app to manage SF customizations. The three main objects are Project, Requirements w/ master-detail to Project and UATs w/ master-detail to Requirements.

I'd like to be able to filter which records are available for the whatid in the Task standard object. I can limit which objects are available to do a lookup on, but I can't filter records to the current Project, its Requirements, and its Requirements UATs.

Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
I've set it up with all three and only the Project Object is being filterered properly.

Strange though. Combining the last from the pic above works without issue, but adding the first filter messes up the other filters. Regardless of order. I've even tried changing the first filter to (param) id. No dice.
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,490 Points 10k badge 2x thumb
Pat,

Could you do this and let me know what you find.

1. Put back all three conditions with model merges
2. For each object type, inspect the network traffic coming back from the server to get the SOQL being generated for each search like in the picture below. To do this, click on the network tab of your chrome console. Then make sure the red "record" button is on. Next clear out all other network logs. Then do your search. An "apexremote" item should show up in your network log. Click on that and then go to the "Response" tab. Look through the response for the SOQL query that was generated.



3. Post the SOQL queries
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
First: SELECT Name,Id FROM Project_mB__c WHERE ((Id = 'a5q70000000s0qoAAA')) ORDER BY Name LIMIT 51

Second: SELECT Name,Id FROM Requirement_mB__c WHERE ((Project__c = 'a5q70000000s0qoAAA'))AND((Id = 'a5q70000000s0qoAAA')) ORDER BY Name LIMIT 51

Third: SELECT Name,Id FROM UAT__c WHERE ((Requirement__r.Project__c = 'a5q70000000s0qoAAA'))AND((Id = 'a5q70000000s0qoAAA')) ORDER BY Name LIMIT 51

For some reason, the condition from the first filter is sneaking into the second and third filter.
Photo of Ben Hubbard

Ben Hubbard, Employee

  • 12,490 Points 10k badge 2x thumb
Thanks Pat, I think this is a bug in Skuid then. I think it's looking at if that particular object has that particular field, and if so, it's using it in the filter. (Obviously all object have Id fields)

A workaround would be to create a formula field on your project object that just referenced the Id field, but was called something different. Specifically, named something that was not a field name on the Requirement or UAT objects.
Photo of mB Pat Vachon

mB Pat Vachon, Champion

  • 42,714 Points 20k badge 2x thumb
That fixed it.

I'm glad it wasn't me. I was starting to wonder why it was doing this.