# Implementing a User Defined Record Filter String in a Report

**URL:** <https://clarionhub.com/t/implementing-a-user-defined-record-filter-string-in-a-report/6432>\
**Category:** questions\
**Tags:** report\
**Created:** [July 26, 2023, 9:41am UTC](https://clarionhub.com/t/implementing-a-user-defined-record-filter-string-in-a-report/6432 "2023-07-26T09:41:23Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![NeutronBoy](https://clarionhub.com/user_avatar/clarionhub.com/neutronboy/32/4355_2.png) [@NeutronBoy](https://clarionhub.com/u/NeutronBoy)\
**Post date:** [July 26, 2023, 9:41am UTC](https://clarionhub.com/t/implementing-a-user-defined-record-filter-string-in-a-report/6432/1 "2023-07-26T09:41:23Z")

</div>

Hi All

I want to filter a report based on some selection(s) that a user has made in a another window and are dumped into a string. I want that string to be the expression used in the Report Properties like as shown below. I seem to recall that I need to put some special characters before the GLO:Filter entry to make this work right. I cant remember how this is done.

![image](https://clarionhub.com/images/transparent.png)

---

<div class="post-metadata">

**Author:** ![seanh](https://clarionhub.com/letter_avatar_proxy/v4/letter/s/4af34b/32.png) [@seanh](https://clarionhub.com/u/seanh)\
**Post date:** [July 26, 2023, 10:14am UTC](https://clarionhub.com/t/implementing-a-user-defined-record-filter-string-in-a-report/6432/2 "2023-07-26T10:14:39Z")

</div>

!Glo:Filter  
The ! says its a variable

---

<div class="post-metadata">

**Author:** ![amardeep\_srivastav](https://clarionhub.com/letter_avatar_proxy/v4/letter/a/ac91a4/32.png) [@amardeep\_srivastav](https://clarionhub.com/u/amardeep_srivastav)\
**Post date:** [July 26, 2023, 1:06pm UTC](https://clarionhub.com/t/implementing-a-user-defined-record-filter-string-in-a-report/6432/3 "2023-07-26T13:06:19Z")

</div>

That is fine you are using that Glo:Filter, but if you want to filter the report data then you can use QUEUE and filter the queue based on the filter option selected then display the records.

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [July 26, 2023, 3:43pm UTC](https://clarionhub.com/t/implementing-a-user-defined-record-filter-string-in-a-report/6432/4 "2023-07-26T15:43:30Z")

</div>

> [@seanh](#):
>
> !Glo:Filter  
> The ! says its a variable

I had School example open and took some captures showing the Exclamation makes it generate a simple assignment as Filter:

 ![image](https://clarionhub-uploads.s3.eu-north-1.amazonaws.com/original/2X/a/a859c7328002f5339d9bd8e36fc5b5e28e4666ef.png)

 ![image](https://clarionhub-uploads.s3.eu-north-1.amazonaws.com/original/2X/5/5e6a33cf91fc8fd26d0ad36d68efbaa4b72d7d0c.png)

This is common in many of the templates, but not all.

---

<div class="post-metadata">

**Author:** ![NeutronBoy](https://clarionhub.com/user_avatar/clarionhub.com/neutronboy/32/4355_2.png) [@NeutronBoy](https://clarionhub.com/u/NeutronBoy)\
**Post date:** [July 26, 2023, 7:03pm UTC](https://clarionhub.com/t/implementing-a-user-defined-record-filter-string-in-a-report/6432/5 "2023-07-26T19:03:37Z")

</div>

thank you both … BTW Carl, I have wondered about the topic of example files … I don’t seem to get any when I did full installs for C8. Are they somewhere else?

---

<div class="post-metadata">

**Author:** ![NeutronBoy](https://clarionhub.com/user_avatar/clarionhub.com/neutronboy/32/4355_2.png) [@NeutronBoy](https://clarionhub.com/u/NeutronBoy)\
**Post date:** [July 26, 2023, 7:27pm UTC](https://clarionhub.com/t/implementing-a-user-defined-record-filter-string-in-a-report/6432/6 "2023-07-26T19:27:44Z")

</div>

One other issue (I have lots of them 🙂 ):  
LEGACY CODE: The filters I am using are on two fields: SCH:Date and SCH:MachineName. Things go great when I filter on the date and variations on the date (start/end dates), but when I filter on machine name, I am getting this error:

 ![image](https://clarionhub-uploads.s3.eu-north-1.amazonaws.com/original/2X/5/58a6bb3b55f6cba045ee6e6172f1a3263ed8a7d0.png)

The Sessions file is a child to the SCH file. I am not doing any filtering on the Child file. The Report is simply printing the Parent Header (SCH:) along with the linked Child (Sessions) data.

I have researched that error and it seems that there it has been longstanding and that there is no workaround (staying in template land) and may require hand coding. TRUE?

I should add that the SCH: file consists of DATE and MachineName.

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [July 26, 2023, 10:29pm UTC](https://clarionhub.com/t/implementing-a-user-defined-record-filter-string-in-a-report/6432/7 "2023-07-26T22:29:40Z")

</div>

To help spot the problem you’ll have to show the contents of your filter string throwing the error i.e. Glo:Filter .

One likely issue is you must BIND() any variables you use in that String. Is “Laser” a variable?

E.g. if `Glo:Filter='SCH:MachineName = MachineWanted'`  
you’ll must have done a `BIND('MachineWanted',MachineWanted )`.  
Search the source for BIND and add yours near there.

> [@NeutronBoy](#):
>
> Things go great when I filter on the date and variations on the date (start/end dates), but when I filter on machine name, I am getting this error:

If you are trying to match the literal “Laser” your filter string will need quotes around that literal e.g.  
`Glo:Filter='SCH:MachineName = ''Laser'' '`. While matching a Number does not need quotes e.g. `Glo:Filter='SCH:Date = 80808 '`

There is a QUOTE() function to help.

---

<div class="post-metadata">

**Author:** ![NeutronBoy](https://clarionhub.com/user_avatar/clarionhub.com/neutronboy/32/4355_2.png) [@NeutronBoy](https://clarionhub.com/u/NeutronBoy)\
**Post date:** [July 26, 2023, 10:36pm UTC](https://clarionhub.com/t/implementing-a-user-defined-record-filter-string-in-a-report/6432/8 "2023-07-26T22:36:28Z")

</div>

Here is the part of the filter building code that is meessing up:

```auto
        IF LEN(CLIP(GLO:MachineFilter)) > 0 
            IF LEN(CLIP(GLO:Filter)) > 0 ! to append or not
                GLO:Filter = CLIP(GLO:Filter) & ' AND Sch:MachineName = ' & CLIP(GLO:MachineFilter)
            ELSE
                GLO:Filter = 'Sch:MachineName = ' & CLIP(GLO:MachineFilter)
            .
        .  

```

The last part of the IF is goofing up. GLO:MachineFilter gets filled by a dropdown list. It contains the value ‘Laser’ from the dropdown. Sch:MachineName is a field from the file being filtered. Sessions is a child file to SCH and is not in the filter, but is shown in the report as a child file. The child processes fine when the MachineFilter stuff is not in the filter.

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [July 26, 2023, 11:06pm UTC](https://clarionhub.com/t/implementing-a-user-defined-record-filter-string-in-a-report/6432/9 "2023-07-26T23:06:48Z")

</div>

A literal needs to be in Single Quotes. Quotes must be doubled in Source. That can be hard to see so some use `<39>` or CHR(39). Show the Filter in a message or debug to be sure what you have. QUOTE()

```auto
GLO:Filter = 'Sch:MachineName = ''' & QUOTE(CLIP(GLO:MachineFilter)) &''''
! or with <39> for Single Quote as more visible
GLO:Filter = 'Sch:MachineName = <39,39>' & QUOTE(CLIP(GLO:MachineFilter)) & '<39,39>'

```

* * *

You have your filter code 2 Times, once adds an `' AND '` to append to existing filter. That’s a pain. There are a few ways to eliminate that, like using `CHOOSE(Condition, True Value, False Value)` that is an IF Function to append the " AND ".:

```auto
  IF GLO:MachineFilter THEN !Is it Not Blank? 
       GLO:Filter = CHOOSE(~GLO:Filter,'', CLIP(GLO:Filter) & ' AND ') & | 
            'Sch:MachineName = <39,39>' & QUOTE(CLIP(GLO:MachineFilter)) & '<39,39>'
  END 

```

* * *

A simpler way to deal with that is to always insert the `'AND '`. Then at the end of your concatenation code check IF the Filter starts with `' AND '` then remove it:

```auto
  IF GLO:DateFilter THEN !Is it Not Zero? 
       GLO:Filter = CLIP(GLO:Filter) & ' AND ' & | 
            'Sch:Date = ' & GLO:DateFilter
  END
  IF GLO:MachineFilter THEN !Is it Not Blank? 
       GLO:Filter = CLIP(GLO:Filter) & ' AND ' & | 
            'Sch:MachineName = <39,39>' & QUOTE(CLIP(GLO:MachineFilter)) & '<39,39>'
  END
  IF SUB(GLO:Filter,1,5)=' AND ' THEN !Starts with just " AND " ?
       GLO:Filter=LEFT(SUB(GLO:Filter,6, SIZE(GLO:Filter) ) !Reomve first 5 byteswith 'AND '
  END 

```

---

<div class="post-metadata">

**Author:** ![NeutronBoy](https://clarionhub.com/user_avatar/clarionhub.com/neutronboy/32/4355_2.png) [@NeutronBoy](https://clarionhub.com/u/NeutronBoy)\
**Post date:** [July 27, 2023, 1:30pm UTC](https://clarionhub.com/t/implementing-a-user-defined-record-filter-string-in-a-report/6432/10 "2023-07-27T13:30:49Z")

</div>

Consider this: The filter on the Report works when I just reduced it to the following:

`Sch:MachineName = GLO:MachineFilter`

Granted that is the directly entered in the the Record Filter entry in the Report Properties, and not part of a string in GLO:FIlter. Why should it not work as part of the string? No quotes are needed for the expression as it does not contain any literals.

---

<div class="post-metadata">

**Author:** ![CarlBarnes](https://clarionhub.com/user_avatar/clarionhub.com/carlbarnes/32/1859_2.png) [@CarlBarnes](https://clarionhub.com/u/CarlBarnes)\
**Post date:** [July 27, 2023, 5:45pm UTC](https://clarionhub.com/t/implementing-a-user-defined-record-filter-string-in-a-report/6432/11 "2023-07-27T17:45:22Z")

</div>

> [@NeutronBoy](#):
>
> Consider this: The filter on the Report works when I just reduced it to the following:
> 
> `Sch:MachineName = GLO:MachineFilter`

That is typical Filter code with a `File Variable = Variable with Value I Want `. That Value Variable works because it is BINDed.

All the answers are in the Generated code. Open the Embeditor and search for GLO:MachineFilter. You should find these 2 lines:

```auto
Process:View{PROP:Filter}='Sch:MachineName = GLO:MachineFilter'

BIND('GLO:MachineFilter',GLO:MachineFilter)

```

The Templates spotted you used GLO:MachineFilter in a Filter and added the BIND so it would work in FILTER. Without that BIND you get error 1011. Read the Help on BIND, FILTER and EVALUATE.
