cancel
Showing results for 
Search instead for 
Did you mean: 

Setting Date value in header using dynamic expression

SOLVED
richie
Community Hero

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

 

 

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
1 ACCEPTED SOLUTION

Accepted Solutions
richie
Community Hero

Re: Setting Date value in header using dynamic expression

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

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta

View solution in original post

1 REPLY 1
richie
Community Hero

Re: Setting Date value in header using dynamic expression

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

if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta

View solution in original post

New Here?
Join us and watch the welcome video:
Announcements
Top Kudoed Authors