We've updated the ServiceNow Community Code of Conduct, adding guidelines around AI usage, professionalism, and content violations. Read more

Script to configure the filters in the UI Builder

Arun Kumar 659
Tera Contributor

In the Platform Analytics Academy - Crafting Insights with UI Builder, they have used a specific script to bind the the Filters with the other elements.

 

YouTube video - https://www.youtube.com/watch?v=rK7JuNJrLEw&list=PLkGSnjw5y2U6HotK0MQUbCrzVog_zBWat&index=11

 

A small part of it is not visible and I was unable to make out what it could be. Can any of you please share it if possible.

1 ACCEPTED SOLUTION

Kevin83
ServiceNow Employee

I think this is the script you are referring to:

function handler({ api, event, helpers, imports }) {
	const mergePARFiltersV2 = imports["global.mergePARFilters"]().v2;
	const { appliedFilters } = event.payload;
	api.setState("parFilters", ({ currentValue, api }) => {
		const { parFilters, encodedQueries } = mergePARFiltersV2(
			currentValue,
			appliedFilters
		);
		api.setState("encodedQueries", encodedQueries);
		return parFilters;
	});
}

View solution in original post

3 REPLIES 3

Kevin83
ServiceNow Employee

I think this is the script you are referring to:

function handler({ api, event, helpers, imports }) {
	const mergePARFiltersV2 = imports["global.mergePARFilters"]().v2;
	const { appliedFilters } = event.payload;
	api.setState("parFilters", ({ currentValue, api }) => {
		const { parFilters, encodedQueries } = mergePARFiltersV2(
			currentValue,
			appliedFilters
		);
		api.setState("encodedQueries", encodedQueries);
		return parFilters;
	});
}

Yes absolutely, thanks for sharing!!

Also, this is in the Component reference on the dev site. This reference is the go-to for configuring any UIB component. https://developer.servicenow.com/dev.do#!/reference/next-experience/xanadu/shared-components/sn-comp... (You have to scroll down as the internal page links don't work.)