Question

Filter lookup values based on multi select dropdown

  • 30 March 2023
  • 11 replies
  • 209 views

Badge +3

Hello,

I am creating a script that will allow the task_types to appear according to the chosen task_category. 

If I choose multiple task_categories, then in the task_type lookup it should appear all the values that are beloging to the task categories that I have chosen. 

 

This is running on the filters of the Task List screen. 

I created this script that already allows me to do that, but there is a bug, if I choose multiple task_types, the task_type label only fills me with one.

var taskCategory = getControlValue('task','task_category');


var activeCriteria={};
    activeCriteria['locked'] = 'Y';
    activeCriteria['itemName'] = '';
    activeCriteria['functionItemName'] = 'global_code_table.active';
    activeCriteria['value'] = 'Y';

var codeNameCriteria = {};
    codeNameCriteria['locked']='Y';
    codeNameCriteria['itemName'] = '';
    codeNameCriteria['functionItemName'] = 'global_code_table.code_name';
    codeNameCriteria['value'] = 'task_type'; 

var codeValueCriteria={};   
    codeValueCriteria['locked']='N';
    codeValueCriteria['itemName'] = '';
    codeValueCriteria['functionItemName'] = 'global_code_table.code_value';
    codeValueCriteria['value'] = ; 
    
var oriSystemCriteria={};  
    oriSystemCriteria['locked'] = 'Y';
    oriSystemCriteria['itemName'] = '';
    oriSystemCriteria['functionItemName'] = 'global_code_table.user_def3';
    oriSystemCriteria['value'] = taskCategory;

var navItems={};
    navItems.searchCriteria={};
    navItems.searchCriteria['global_code_table.code_value']= codeValueCriteria;
    navItems.searchCriteria['global_code_table.code_name']= codeNameCriteria;
    navItems.searchCriteria['global_code_table.active']= activeCriteria;
    navItems.searchCriteria['global_code_table.user_def3']= taskCategory;
    

    var selectComp=openPopup('TASK_CATEGORY_LOOKUP',navItems);
    
    
    
    if (selectComp.selectedRow)
{
    
    setControlValue('task','task_type',selectComp.selectedRow.data['global_code_table.code_value']);

   } 
    

 For example : I open the task_type lookup and select 2 lines, and when I hit the search button, the task_type label only shows one value and it only searches for the value that is populated and not the two I chose.
    
 Does anyone know a better way of doing this kind of filterting /dependency or how I can resolve this error ? 

 


11 replies

Userlevel 6
Badge +26

Hey @Carlos123 

Can you please add a screen capture? I find it hard to follow the scenario.

 For example : I open the task_type lookup and select 2 lines, and when I hit the search button, the task_type label only shows one value and it only searches for the value that is populated and not the two I chose.

What search button you click? You should click ‘OK’ and then the values are populated with ‘OR’ sign between them.

Seems like the issue is with your first selection from the first lookup and not with the code to begin with.

Example multi value lookup search - 

 

Cheers!

Badge +3

Hello @Shneor Cheshin 

Imagine I chose the two values, when I pressed ok it only put the first one in. 

 

 I think there is a problem, when I open the lookup with the field already populated, as above, and go to the filters the code value is not populated

 

Cheers!

Userlevel 6
Badge +26

Hey @Carlos123 

As I wrote in my first reply

Can you please add a screen capture? I find it hard to follow the scenario.

 

Cheers!

Badge +3

Hello,
Imagine, when we open a lookup, a list of data appears there, and we can select more than one line, and the field will appear like this

 

but in my lookup this doesn't happen, it only pops up one value, I think it's because of the code.

Cheers

Userlevel 6
Badge +26

Hey @Carlos123 

So what is the purpose of the code? If it is causing issues, remove it.

Cheers!

Badge +3

hello @Shneor Cheshin 

the purpose of the code is to populate a user_def of the task types' global code to show only the task types depending on the chosen task_category.

Cheers

Userlevel 6
Badge +26

Hey @Carlos123 

Sorry, but I am not following. It will be better if you provide a full flow of the required functionality.

If I understand correctly this is the flow

  1. Choose task category(ies) from a lookup filed.
  2. Populate task types that relate to the choosen task category(ies) in step 1.

Is that correct?

If so, you need to populate the values on the lookup click event of the task type lookup.

Cheers!

Badge +3

Hello,

the task_category is as dropdown, because it has few values.


The task type is as lookup where, I popped up a user def with the corresponding task_category values.


In the task_type lookup I added one more field in the filter which is this user def.
This was the process.


About populating the values in the lookup, I wanted that user def to populate itself, dynamically.

 

Cheers

Userlevel 6
Badge +26

Hey @Carlos123 

The demo below is meaningless from business perspecitve, I just wanted to show how the functionality work.

In this demo I

  • Choose a couple of task statuses from a drop down.
  • Populate the values in the person lookup. person_id field

 

The code

//get value of task status dropdown
var controlValue = getControlValue('task','task_status');
//prepare search items for lookup
var navigationItem = {};
navigationItem.searchCriteria = {};
navigationItem.data = {};
//check there are values in the field
if (isNullOrEmptyString(controlValue) == true)
{
navigationItem.searchCriteria['person.person_id'] = '';
}
else
{
navigationItem.searchCriteria['person.person_id'] = controlValue;
}
//open the lookup window
openPopup('PERSONLOOKUP', navigationItem);

 

Hope this is the scenario you are trying to achieve.

Cheers!

Badge +3

Hello, thank you, 

But the problem is not the populate of the person ID field you showed, it is later when you choose two owners and it populate the two person IDs in the owner field, I don't know if I explained myself well

Cheers!

Userlevel 6
Badge +26

@Carlos123 

As explained before. Use the ctrl key to select multi values

 

Cheers!

Reply