Forum Discussion

mwalter's avatar
mwalter
Occasional Contributor
9 years ago

How to reference an Environment property from the custom headers of a request

I need some help with my usage or syntax reading an Environment property.  I have a custom header property that I need to add to every request.  In essence it defines the back-end that goes with each...
  • Radford's avatar
    9 years ago

    Are you talking about using the custom properties that are displayed in the Environment dialog box? If so these are project custom properties.

     

    While I have never referenced them for the exact scenario you describe, via Groovy script you would reference them by with the following property expansion syntax:

     

    ${#Project#FirmId}

     

    Might be worth a try...

  • dg3781's avatar
    dg3781
    9 years ago

    mwalter wrote:

    Hmmm....this is rather interesting.   I ran your example and saw the same issue as you.  Then I re-ran mine, and it is also now showing the same problem where it previously worked.


    OK I figured out how to make this work. The idea is to perform the property expansion using the context variable because that's what is available within the scope of the script when RequestFilter is used.

     

    def key = context.expand('${#Project#az_key}')

     

    Then i can use key as a variable to set the header i need:

     

    headers.put("Authorization", key)

     

    Hope this helps others!

  • mwalter's avatar
    mwalter
    9 years ago

    dg3781,

    Yes, that actually does help and works well.  So thank you for that.   It still baffles me why the original solution stopped working.  My initial thought was that something changed with the 1.9.0 version because I did upgrade in between these 2 attempts but whatever, after I applied your change my script started working again.