Forum Discussion

richie's avatar
richie
Community Hero
7 years ago

Setting Date value in header using dynamic expression

Hey,

 

I have a POST request that includes a custom header.

 

The header (entitled 'filename') has a value with the format of 'UniqueID_datevalue.txt' (something like T1234567_170818.txt).

 

I have a subsequent GET request that uses the header value to filter the GET query.  At the moment I manually change the ddmmyy date value in the header on the POST everyday and I was thinking I should be able to make this dynamic with a bit of groovy (I was reading about Dynamic Expression).

 

I was looking at the Date() method - so what I've got so far is as follows:

 

T1234567_${=(new Date().format('ddmmyy'))}.txt

 

HOWEVER - it works, but it doesn't always generate the header value with a valid month - sometimes it is a value of 01 to 12, other times the month value has been 33 and 47 (e.g. 293318 and 294718).

 

Does anyone know why the month portion of the string is not working correctly?

 

Thanks to all!

 

richie

 

 

  • aah  - I'm an idiot

     

    If anyone else gets stuck around this when trying to use the Date method - make sure your month in the string is UPPER case MM, rather than mm.

     

    I'm guessing mm equates to minutes considering the numbers that were generated, whereas MM equates to months!

     

    Cheers,

     

    rich

  • richie's avatar
    richie
    Community Hero

    aah  - I'm an idiot

     

    If anyone else gets stuck around this when trying to use the Date method - make sure your month in the string is UPPER case MM, rather than mm.

     

    I'm guessing mm equates to minutes considering the numbers that were generated, whereas MM equates to months!

     

    Cheers,

     

    rich