Forum Discussion

Armytech's avatar
Armytech
New Contributor
4 months ago

Date as a Global property

Hi

 

How do I set date as a global property?

I need to set a global property that when I send the API request it will then input the current date into the call and return what i need.

Regards ArmyTech

3 Replies

  • groovyguy's avatar
    groovyguy
    Community Hero

    What nastester​ posted works. You can use a property value of an inline groovy script expression, which is what ${=Calendar.instance.time.format("yyyy-MM-dd")}. Every time you reference it and send it, say in a request, it'll grab basically a now() timestamp.

    If you put it in a variable called Date, you just put ${#Global#Date} in where you want that timestamp.

     

  • nastester's avatar
    nastester
    Regular Contributor

    I haven't tried this personally but I would think you'd be able to use Calendar.instance

    ${=Calendar.instance.time.format("yyyy-MM-dd")}