# How to get clause from segment in smart collection route

**URL:** <https://community.forestadmin.com/t/how-to-get-clause-from-segment-in-smart-collection-route/4580>\
**Category:** Help me!\
**Created:** [April 27, 2022, 1:43pm UTC](https://community.forestadmin.com/t/how-to-get-clause-from-segment-in-smart-collection-route/4580 "2022-04-27T13:43:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Simon\_BRAMI1](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/simon_brami1/32/2753_2.png) [@Simon\_BRAMI1](https://community.forestadmin.com/u/Simon_BRAMI1)\
**Post date:** [April 27, 2022, 1:43pm UTC](https://community.forestadmin.com/t/how-to-get-clause-from-segment-in-smart-collection-route/4580/1 "2022-04-27T13:43:48Z")

</div>

Hi!

I have created a smart collection, I want to create smart segments, how do I retrieve the “where” clause of my segment when I’m in the route of `/myCollection` list function ?

`request.query.segment` only contains the name of the segment 😛

Thank you 🙂

---

<div class="post-metadata">

**Author:** ![Simon\_BRAMI1](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/simon_brami1/32/2753_2.png) [@Simon\_BRAMI1](https://community.forestadmin.com/u/Simon_BRAMI1)\
**Post date:** [April 27, 2022, 2:20pm UTC](https://community.forestadmin.com/t/how-to-get-clause-from-segment-in-smart-collection-route/4580/2 "2022-04-27T14:20:29Z")

</div>

At this time I have created a variable that knows the condition of each segment:

```javascript
const segmentCondition = {
    'Active': {
      activeFrom: {
        [Op.ne]: null
      },
      activeTo: null
    },
    'Dafts ✏️': {
      activeFrom: null,
      activeTo: null
    }
  }

```

And then put it inside the WHERE clause:

```javascript
const list = await models.someTable.findAll({
    where: { 
     ...
      ...segmentCondition[request.query.segment]
    }
  })

```

but if there’s is a cleaner way to get my where clause directly from /forest folder, please HMU 😛

---

<div class="post-metadata">

**Author:** ![anon39848301](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@anon39848301](https://community.forestadmin.com/u/anon39848301)\
**Post date:** [April 27, 2022, 4:07pm UTC](https://community.forestadmin.com/t/how-to-get-clause-from-segment-in-smart-collection-route/4580/3 "2022-04-27T16:07:10Z")

</div>

Hey @Simon_BRAMI1 👋

I’m not totally sure to have understand your issue.  
Do you want to create a Smart Segment on your Smart Collection? If that’s the case, I’m guessing that your mentioned solution would be the way to go.

What bother you in your current implementation?

Thanks in advance 🙏

---

<div class="post-metadata">

**Author:** ![Simon\_BRAMI1](https://dub1.discourse-cdn.com/flex013/user_avatar/community.forestadmin.com/simon_brami1/32/2753_2.png) [@Simon\_BRAMI1](https://community.forestadmin.com/u/Simon_BRAMI1)\
**Post date:** [April 28, 2022, 3:56pm UTC](https://community.forestadmin.com/t/how-to-get-clause-from-segment-in-smart-collection-route/4580/5 "2022-04-28T15:56:54Z")

</div>

Hi jeff,

I just wanted to avoid duplicate code if there was a method to retrieve the where condition directly into my route !  
But anyways that solution works just fine 😉

Thank you!
