# Pass a channel variable to another channel

**URL:** <https://community.asterisk.org/t/pass-a-channel-variable-to-another-channel/35207>\
**Category:** Asterisk Support\
**Created:** [May 11, 2011, 5:26pm UTC](https://community.asterisk.org/t/pass-a-channel-variable-to-another-channel/35207 "2011-05-11T17:26:09Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/asterisk/original/2X/4/475d0c889911cfb84ac4881ad6df8b523e3f9105.png) [@system](https://community.asterisk.org/u/system)\
**Post date:** [May 11, 2011, 5:26pm UTC](https://community.asterisk.org/t/pass-a-channel-variable-to-another-channel/35207/1 "2011-05-11T17:26:09Z")

</div>

Hi,

I am using an originate action to make an outbound call to someone and then connect the call to an IVR.  
In this case, 2 channels will be created. I’m wondering how to pass a channel variable from the first channel to the second using dial plan or AMI. Please note I have to avoid using global variables. Thanks.

---

<div class="post-metadata">

**Author:** ![david55](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@david55](https://community.asterisk.org/u/david55)\
**Post date:** [May 11, 2011, 5:35pm UTC](https://community.asterisk.org/t/pass-a-channel-variable-to-another-channel/35207/2 "2011-05-11T17:35:58Z")

</div>

Why can’t you use global variables? Which version of Asterisk are you using?

The is a mechanism, available in 1.6 (at least 1.6.1+) which looks like it would support this, but it may have some of the attributes of global variables that you want to avoid.

AMI methods should be obvious.

I get worried when I see arbitrary, but absolute, constraints, that the question may be a homework one.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/asterisk/original/2X/4/475d0c889911cfb84ac4881ad6df8b523e3f9105.png) [@system](https://community.asterisk.org/u/system)\
**Post date:** [May 11, 2011, 6:34pm UTC](https://community.asterisk.org/t/pass-a-channel-variable-to-another-channel/35207/3 "2011-05-11T18:34:27Z")

</div>

I am working on an AMI app that makes multiple concurrent outbound calls. It first calls someone, and then connects the call to an IVR. I need to find a reliable way to filter out unwanted events from Asterisk so that each thread handles only relevant events. I’m trying to see if that is doable with channel variables. I can set the variable along with each originate action, but the variable is only available in the first channel. I need to pass it to another channel and hope the variable will show up in one of the subsequent events. Obviously, global variables are not a good option because of multiple concurrent calls.

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/asterisk/original/2X/4/475d0c889911cfb84ac4881ad6df8b523e3f9105.png) [@system](https://community.asterisk.org/u/system)\
**Post date:** [May 20, 2011, 1:13pm UTC](https://community.asterisk.org/t/pass-a-channel-variable-to-another-channel/35207/4 "2011-05-20T13:13:19Z")

</div>

You can use the Set variable  
exten =\> s,n,Set(\_\_MCall=${anyvalue})

Now you can use \_\_MCall variable one channel to another. Global variable overrite the previous value.

Make Sure about double underscore with variable name.

I hope this helps you.

---

<div class="post-metadata">

**Author:** ![david55](https://avatars.discourse-cdn.com/v4/letter/d/e19adc/32.png) [@david55](https://community.asterisk.org/u/david55)\
**Post date:** [May 20, 2011, 1:37pm UTC](https://community.asterisk.org/t/pass-a-channel-variable-to-another-channel/35207/5 "2011-05-20T13:37:08Z")

</div>

The variable is passed by value, not by name/reference, and only to channels created by the channel on which it is set, and its descendents.

(I have some reservations about the likely application here.)
