How to use CHANNEL variables

Hi.

2 asterisk boxes A & B are connected together in IAX (main) and PJSIP
(failover), the B one doing outgoing calls to the world in PJSIP.

When something is wrong on asterisk B before sending the call outside
(eg number not allowed, wrong format, …) we would like to send info
back to asterisk A.

We tried by setting CHANNEL variables like namedpickupgroup or
hangupsource but the first one stay with his original value as the
second one is resetted to empty string.

What is the way to do this? Remember, should be independant from technology.

Regards

Daniel