How to replace an already set variable from custom extensions

So, I have a Dynamic Route that sets a variable when a user can be verified by their id number.

This ID number is saved as a variable called [stdt_id]. Upon an API lookup. Upon validation, It will return the name of the user, this variable is saved as [sid-name].

Here is how it goes:

  1. If user is authenticated and exist on our database, then [sid-name] = name.user
  2. If user is not found on our database then the [sid-name] = NULL
  3. If user doesn’t know their id number, API lookup is skipped.

Then I have a queue that shows the name of the user within the CID name prefix

Here is how it displays in the phone based on the given scenarios:

  1. Queue: name.user - (number)
  2. Queue: NULL - (number)
  3. Queue: [empty spaces] - (number) <<========== This is what I am trying to change.

If you can see on the (3rd) scenario, the user skipped the API lookup and the variable [sid-name] is empty, thus the spacing.

I am trying so that if the user skips the API lookup, then I sent the call to a custom extension that replace the empty variable [sid-name] to a character such as an asterisk (*), so that the queue would display something like: Queue: * - (number).

I am not sure if this is possible, I’m looking for something like:

exten => s,n,GotoIf($["${ARG1}" = ""]?skip)    // Matches if [sid-name] is an empty variable.
exten => s,n(skip),Set(--Replace DYNROUTE variable-- = *)        // Replaces DYNROUTE variable to [*]
exten => s.n,Return

Any help would be amazing! Thank you :smiley:

If you wanted to keep it in the GUI, you could do an additional dynamic route where your set DYNROUTE_sid-name to the desired variable, prior to going to queue. an asterisk command of LEN to see if it needs the treatment, then a second route that uses the set command in Asterisk.

Is there a CLI solution? If I’m being honest, I have already a lot of Dyn Routes and I would prefer not to add more unless extremely necessary.

Of course. The CLI is the dialplan. I would make a context in extensions_custom.conf, add [ext-queues-custom]. there is already a hook for [ext-queues-custom] in [ext-queues].

Yep, that’s exactly what I’m trying to accomplish.

I have already an extension_custom.conf created and is being referenced in the Custom Destinations Module.

I have two arguments. The second argument is what I am trying to change to an asterisk whether “LEN” as you mention equals 0.

Do you know how the dialplan would look like in this scenario? Sorry I have no much experience with Asterisk dialplans within the cli. I’m trying to learn a bit more

This is what my dialplan looks like at the moment:

exten => s,n,GotoIf($["${ARG2}" != "NULL"]?cdr-in)     // Match if [sid-name] = Not Null
exten => s,n,GotoIf($["${ARG2}" = "NULL"]?null)        // Match if [sid-name] = Null
exten => s,n(cdr-in),Set(CDR(userfield)=${ARG1})
exten => s,n,Return
exten => s,n(null),Noop(cdr-userfield(Skipped)=${ARG1}:NULL)
exten => s,n,Return

You need to state in what context that snippet exists

Just put this in extension_custom.conf, no need to make a custom destination and weave it in, since the [ext-queues] includes it by default. This assumes the variables exist earlier in the channel.

exten => s,n,GotoIf($[“${LEN(${DYNROUTE_sid-name})” = “0”]?null)
exten => s,n,Set(CDR(userfield)=${DYNROUTE_stdt_id})
exten => s,n,Return
exten => s,n(null),Noop(cdr-userfield(Skipped)=${DYNROUTE_stdt_id}:NULL)
exten => s,n,Return

The s extension will only match an extension otherwise previously unmatched, the level of 'inclusion’s is critical. What did you dial ? (dialplan show)

You’re making this way harder than it needs to be, and I don’t think your attempts to hook queue dialplan are going to work.

It looks like your goal is to define an asterisk expression that will display a channel variable value if not null, otherwise display a different fixed value. If that’s so, then this is what you want:


which you can sub directly into the queue CID prefix field like so:

Queue: ${IF($["${DYNROUTE_sid-name}"=""]?*:${DYNROUTE_sid-name})} -

No conf file edits required.

1 Like

Works like a charm! Thanks for the help y’all! I think I like to overcomplicate myself haha! That is so much easier to deploy! No need for extra config to be included!

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.