Forum Discussion

breaux's avatar
breaux
Contributor
9 years ago
Solved

Dynamic date REST parameter?

Is there any way to define a REST parameter that will automatically take like tomorrow's date?

 

I tried this, but don't know what's really possible or what the syntax would be for more complicated steps:

 

${=import java.util.Calendar; Calendar now=Calendar.getInstance(); now = now.add(Calendar.DATE, 1); new java.text.SimpleDateFormat("yyyy-MM-dd").format(now.getTime())}

 

According to the raw value, "now" is null when now.getTime() is called.

  • Or, this seemed to give the next days date and could be inserted as a REST parameter:

     

    ${=def now = new Date();now++;now.format("yy-MM-dd")}

7 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3

    This is a working one for soap request, and not tried for REST/Json, would you like to try below one?

     

    ${=import java.text.SimpleDateFormat; import java.util.Date;def date=new Date();new SimpleDateFormat("yyyy-MM-dd").format(date)}

    • rupert_anderson's avatar
      rupert_anderson
      Valued Contributor

      Or, this seemed to give the next days date and could be inserted as a REST parameter:

       

      ${=def now = new Date();now++;now.format("yy-MM-dd")}
      • breaux's avatar
        breaux
        Contributor

        Beauty, that does it. I think one key miss with my attempt was the "def" keyword.

         

        Presumably that's a Groovy thing. Of Groovy I know pretty much only what looks exactly like Java :-)

         

        Also suprised that Date++ is even possible!

         

        Finally, is there any way to know which classes don't require full package qualification?

  • nmrao's avatar
    nmrao
    Champion Level 3
    May be you want to show how the request is ? and raw request? That will help to correlate easily.