Skip to content

view.ClearFilters

Overview

Clear filter conditions set in the "Server Script". This can be used to disable filters set in the WebUI in the server script.

Filter conditions already set when view.ClearFilters() is called will be deleted. The contents of any new "view.Filters" set in the server script after view.ClearFilters() is called will be valid.

Cautions

  1. Only the "When Processing View" condition can be used.

Syntax

view.ClearFilters();

Parameters

There are no parameters.

Return Value

There is no return value.

Usage Examples

In the example below, all filter operations from the screen are disabled, and then a condition is added to "view.Filters" to extract records that contain the string "Software" in the "Body Column".

JavaScript
view.ClearFilters(); // Disable all filter operations from the screen
view.Filters.Body = 'Software'; // Extract items that contain the string 'Software' in the Body.

Code Samples

1. Control the filter conditions for each user role

Controls the filter conditions as follows.

Role Permission
Privileged user Can view all records
Manager Can view the records of the department they belong to
General employee Can view only the records they are in charge of

For this control, prepare groups as follows and make users members of them.

Role Privileged user group Manager group
Privileged user Member
Manager Member
General employee

In this sample code, they are defined as Privileged user group: GroupId=5 and Manager group: GroupId=4.

Also, to determine whether a record belongs to the department in charge, set ClassA so that a department can be selected.

Then, the filters are controlled as follows.

  • Manager: targets records where ClassA = the user's own department ID
  • General employee: targets records where Owner = the user's own user ID
JavaScript
// Define the group IDs
const ADMIN_GROUP_ID = 5;
const MANAGE_GROUP_ID = 4;
// Determine whether the user belongs to a specific group
function isUserInGroup(userId, groupId) {
    const group = groups.Get(groupId);
    if (!group) return false;
    for (const member of group.GetMembers()) {
        if (member.UserId === userId) return true;
    }
    return false;
}
// Define the rules for applying filters
const rules = [
    {
        name: 'Privileged user group',
        when: () => isUserInGroup(context.UserId, ADMIN_GROUP_ID),
        apply: () => view.ClearFilters(),
    },
    {
        name: 'Manager group',
        when: () => isUserInGroup(context.UserId, MANAGE_GROUP_ID),
        apply: () => {
            const user = users.Get(context.UserId);
            view.Filters.ClassA = `["${user.DeptId}"]`;
        },
    },
    {
        name: 'General employee',
        when: () => true,
        apply: () => {
            view.Filters.Owner = `["${context.UserId}"]`;
        },
    },
];
// Evaluate the rules in order and apply the first matching rule
for (const rule of rules) {
    if (rule.when()) {
        logs.LogInfo(rule.name);
        rule.apply();
        break;
    }
}

Supported Versions

  1. Pleasanter 1.3.13.0 or later