Discussion:
[asterisk-users] AEL: how to check if variable is defined
Klaus Darilion
2008-12-29 18:13:31 UTC
Permalink
Hi!

I use an "if" condition in extensions.ael to check if a channel variable
is defined and if defined I add a certain header:

context toNormaleRufe {
_X. => {
if (${NUMBER}) {
SIPAddHeader(X-NUMBER: ${NUMBER});
};
...
};

This works fine, except NUMBER starts with the + sign.

I tried using quotes but
if ("${NUMBER}")
evaluates always true.

What is the suggested way to solve this?

thanks
klaus
Philipp Kempgen
2008-12-29 19:48:32 UTC
Permalink
Post by Klaus Darilion
I use an "if" condition in extensions.ael to check if a channel variable
context toNormaleRufe {
_X. => {
if (${NUMBER}) {
SIPAddHeader(X-NUMBER: ${NUMBER});
};
...
};
This works fine, except NUMBER starts with the + sign.
I tried using quotes but
if ("${NUMBER}")
evaluates always true.
What is the suggested way to solve this?
if ("${NUMBER}" != "") {
// ...
}

That doesn't tell you whether the variable is defined but in
most cases (if any) that doesn't matter anyway.

Philipp Kempgen
--
http://www.das-asterisk-buch.de - http://www.the-asterisk-book.com
Amooma GmbH - Bachstr. 126 - 56566 Neuwied -> http://www.amooma.de
Geschäftsführer: Stefan Wintermeyer, Handelsregister: Neuwied B14998
--
Philipp Kempgen
2008-12-29 19:54:02 UTC
Permalink
Post by Philipp Kempgen
Post by Klaus Darilion
I use an "if" condition in extensions.ael to check if a channel variable
context toNormaleRufe {
_X. => {
if (${NUMBER}) {
SIPAddHeader(X-NUMBER: ${NUMBER});
};
...
};
This works fine, except NUMBER starts with the + sign.
I tried using quotes but
if ("${NUMBER}")
evaluates always true.
What is the suggested way to solve this?
if ("${NUMBER}" != "") {
// ...
}
That doesn't tell you whether the variable is defined but in
most cases (if any) that doesn't matter anyway.
But I guess it wouldn't hurt to add a DEFINED() function to
Asterisk.

if (DEFINED(myvariable)) {
// ...
}


Philipp Kempgen
--
http://www.das-asterisk-buch.de - http://www.the-asterisk-book.com
Amooma GmbH - Bachstr. 126 - 56566 Neuwied -> http://www.amooma.de
Geschäftsführer: Stefan Wintermeyer, Handelsregister: Neuwied B14998
--
Richard Lyman
2008-12-29 20:18:28 UTC
Permalink
Philipp Kempgen wrote:
*snipped
Post by Philipp Kempgen
But I guess it wouldn't hurt to add a DEFINED() function to
Asterisk.
if (DEFINED(myvariable)) {
// ...
}
Isn't that what ISNULL is for?
Philipp Kempgen
2008-12-29 21:17:21 UTC
Permalink
Post by Richard Lyman
Post by Philipp Kempgen
But I guess it wouldn't hurt to add a DEFINED() function to
Asterisk.
if (DEFINED(myvariable)) {
// ...
}
Isn't that what ISNULL is for?
No. ISNULL() works on values not on variables.

But Dave Fullerton found EXISTS():
http://lists.digium.com/pipermail/asterisk-users/2008-December/224059.html


Philipp Kempgen
--
http://www.das-asterisk-buch.de - http://www.the-asterisk-book.com
Amooma GmbH - Bachstr. 126 - 56566 Neuwied -> http://www.amooma.de
Geschäftsführer: Stefan Wintermeyer, Handelsregister: Neuwied B14998
--
Richard Lyman
2008-12-29 21:57:20 UTC
Permalink
Post by Philipp Kempgen
Post by Richard Lyman
Post by Philipp Kempgen
But I guess it wouldn't hurt to add a DEFINED() function to
Asterisk.
if (DEFINED(myvariable)) {
// ...
}
Isn't that what ISNULL is for?
No. ISNULL() works on values not on variables.
http://lists.digium.com/pipermail/asterisk-users/2008-December/224059.html
Philipp Kempgen
if (${ISNULL(${CAMPAIGN})}) {
Set(CAMPAIGN=INBOUND);
};

This is how i use it.
Klaus Darilion
2008-12-30 06:53:45 UTC
Permalink
Thanks Dave, Philipp and Richard!

klaus
Post by Richard Lyman
Post by Philipp Kempgen
Post by Richard Lyman
Post by Philipp Kempgen
But I guess it wouldn't hurt to add a DEFINED() function to
Asterisk.
if (DEFINED(myvariable)) {
// ...
}
Isn't that what ISNULL is for?
No. ISNULL() works on values not on variables.
http://lists.digium.com/pipermail/asterisk-users/2008-December/224059.html
Philipp Kempgen
if (${ISNULL(${CAMPAIGN})}) {
Set(CAMPAIGN=INBOUND);
};
This is how i use it.
_______________________________________________
-- Bandwidth and Colocation Provided by http://www.api-digital.com --
asterisk-users mailing list
http://lists.digium.com/mailman/listinfo/asterisk-users
Dave Fullerton
2008-12-29 20:45:52 UTC
Permalink
Post by Philipp Kempgen
Post by Philipp Kempgen
Post by Klaus Darilion
I use an "if" condition in extensions.ael to check if a channel variable
context toNormaleRufe {
_X. => {
if (${NUMBER}) {
SIPAddHeader(X-NUMBER: ${NUMBER});
};
...
};
This works fine, except NUMBER starts with the + sign.
I tried using quotes but
if ("${NUMBER}")
evaluates always true.
What is the suggested way to solve this?
if ("${NUMBER}" != "") {
// ...
}
That doesn't tell you whether the variable is defined but in
most cases (if any) that doesn't matter anyway.
But I guess it wouldn't hurt to add a DEFINED() function to
Asterisk.
if (DEFINED(myvariable)) {
// ...
}
Isn't that what EXISTS() is for?

-Dave
Philipp Kempgen
2008-12-29 21:13:40 UTC
Permalink
Post by Dave Fullerton
Post by Philipp Kempgen
But I guess it wouldn't hurt to add a DEFINED() function to
Asterisk.
if (DEFINED(myvariable)) {
// ...
}
Isn't that what EXISTS() is for?
Well, yes. :-)
I've never needed it before and it didn't come to my mind.


Philipp Kempgen
--
http://www.das-asterisk-buch.de - http://www.the-asterisk-book.com
Amooma GmbH - Bachstr. 126 - 56566 Neuwied -> http://www.amooma.de
Geschäftsführer: Stefan Wintermeyer, Handelsregister: Neuwied B14998
--
Loading...