# Check if data is from a CSV or variable

**URL:** <https://community.postman.com/t/check-if-data-is-from-a-csv-or-variable/17719>\
**Category:** Help Hub\
**Created:** [November 15, 2020, 8:04pm UTC](https://community.postman.com/t/check-if-data-is-from-a-csv-or-variable/17719 "2020-11-15T20:04:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jazzycow](https://avatars.discourse-cdn.com/v4/letter/j/b3f665/32.png) [@jazzycow](https://community.postman.com/u/jazzycow)\
**Post date:** [November 15, 2020, 8:04pm UTC](https://community.postman.com/t/check-if-data-is-from-a-csv-or-variable/17719/1 "2020-11-15T20:04:30Z")

</div>

I have collection variables defined, but I also run my collection with a CSV file. In order for either to work I do a check with a pre-request script with

```auto
    if (data['SERIAL']) {
        // data from file
    } else {
       // data from collection variable
    }

```

So I have to check for a specific name I can’t just for example check with

```auto
if (data) {
    // Data from file
} else {

}

```

I’m sure I’m missign something and hoping someone can point me in the right direction.

---

<div class="post-metadata">

**Author:** ![danny-dainton](https://sea2.discourse-cdn.com/getpostman/user_avatar/community.postman.com/danny-dainton/32/29401_2.png) [@danny-dainton](https://community.postman.com/u/danny-dainton)\
**Post date:** [November 15, 2020, 8:39pm UTC](https://community.postman.com/t/check-if-data-is-from-a-csv-or-variable/17719/2 "2020-11-15T20:39:46Z")

</div>

Could you take advantage of the Variable Scope here, if the names are the same?

 ![scopes](https://us1.discourse-cdn.com/getpostman/original/3X/a/4/a423ecd239a2f88ad78eda56f82058025ddda706.jpeg)

> If a variable with the same name is declared in two different scopes, the value stored in the variable with narrowest scope will be used—for example if there is a global and a local variable both named username, the local value will be used when the request runs.

> **[Store and reuse values using variables | Postman Learning Center](https://learning.postman.com/docs/sending-requests/variables/#variable-scopes)**
>
> Store and reuse values using variables: documentation for Postman, the collaboration platform for API development. Create better APIs—faster.

You could get the variable using the `pm.variables.get('var_name')`
