I don’t understand how the first case could possibly work, as it is syntactically invalid.
The correct way of setting Diversion headers, in Asterisk, is with the REDIRECTING function. You shouldn’t try to set it explicitly as it is owned by Asterisk.
I don’t know how well FreePBX handles connected line updates, but it is possible that, with the right high level settings, it may even work automatically.
PS Please markup dialplan (and logs) as pre-formatted text, as the forum can garble them, otherwise, e.g for what you provided
Some of our inbound routes are arriving directly on a custom destination… which forwards the call externally. How can we force a specific number to be set in the Diversion Header using the REDIRECTING function? (using a PJSIP trunk)
I imagine you will need to do it in a pre-dial hook (the same as you would have to do for custom headers).
The same procedure should work for all technologies that can generate a signalling event message equivalent to a SIP Diverson header, i.e. it should work for chan_sip, and may work for ISDN.
Even when setting the value fixed… the Diversion is not showing in the outbound call.
So I guess there is no “better” option than the one I already provided?
Have you enabled send_diversion for the endpoint. I’m not sure if this has been added to the GUI, or whether you will have to use customisation on the endpoint.