Is it possible to use two dynamic filters at the same time?

C_dric Chen
Tera Contributor

Hello, people.

find_real_file.png

I'm creating two groups of buttons, and each group would be bīnded to its own client state parameters, but both groups would apply these client state paramters to the same table. My question is: Is it possible to add two client state parameters into the "Fixed filter" field or the "Filter" field?

Thank you in advance!

1 ACCEPTED SOLUTION

Marc Mouries
ServiceNow Employee
ServiceNow Employee

you can do that by clicking on the code icon "</>" and merging the 2 filters. However, you might be better off using two filter components.

View solution in original post

3 REPLIES 3

Marc Mouries
ServiceNow Employee
ServiceNow Employee

you can do that by clicking on the code icon "</>" and merging the 2 filters. However, you might be better off using two filter components.

Thank you very much!

JuanCruzC
Tera Contributor

Hi C_dric Chen!

I saw you question and I would like to share what I do when I have to build the query from different filters or buttons.

The first things that you have to have done to do this process:
- Client state parameter called query, where you stores the query to send to the fixed filter

-Filters component built with the accurate data. (You can use dropdown also)

-Script to handle and build the query

*To have a clean script I prefer save the values from the filter into a client state parameter, but you can use it directly in the script that I will show you.

Well, first I save the values doing an update client state parameter and after that I trigger the script where I handle the query. (Doesn't matter the applyParFilter is just to return the selected values to the filter)

JuanCruzC_0-1737454815854.png

Note: I updated the client state parameter by script:

function evaluateEvent({api, event}) {
	return {
		propName: "client state parameter name",
		value: event.payload.appliedFilters[0]["values"].toString()
	};
}

 

And this is what the script contains:

function handler({api, event, helpers, imports}) {
//This is my default query that I want allways on my query
    const baseQuery = "active=true^priority=1^categoryIN" + api.state.ecosystem;
// Inicializar partes de la consulta
    let queryParts = [];

 if (api.state.state) {
        queryParts.push(`^stateIN${api.state.state}`);
    }

    if (api.state.assignmentGroup) {
        queryParts.push(`^assignment_groupIN${api.state.assignmentGroup}`);
    }

// Build the final query
    const finalQuery = baseQuery + queryParts.join('');
    api.setState("criticalQuery", finalQuery); 

//Reload the data resource to show the data with the new query
    api.data.look_up_multiple_records_1.refresh();
    api.data.incident_count.refresh();
}


Then you have to add the query parameter into the fixed filter, in my case I added into the data resource but works on the list also.

JuanCruzC_1-1737455354021.png

 

If you have any question I can help you!

 

Thanks,

 

Juan Cruz