Hi Benjamin,
Would you be able to provide a sample of your policy to review? If I understand right, this is the setup you have (example data to get the flow)
Service1 - policy
Encap sets variable ERROR to 10
Set context variable newError = ${ERROR}
msg-completed:
audit ${newError}
Here is a sample of how I was testing and got it to work.
The 'OTK Require OAuth 2.0 Token' returns an error variable named ${ERROR.CODE}. If this errors out the return template allows the policy to proceed (not falsify) and then sets the variable ERROR to ERROR.CODE.
The export then exports ${ERROR} from the policy.
My message complete policy includes a simple audit using the request.shared as Conny noted.
If the return template was excluded the policy would falsify and the variable would not reach the export point.
Perhaps if we can see a sample of what you are working with we can help figure this one out.
Regards,
Joe