Hi, I have a need to extract a date from the body ...
# help
r
Hi, I have a need to extract a date from the body of a soap request and use that in the response. I also need to advance the date by 1 day and use it in the response. I am trying with the below code in response template to figure out a way to do the same, but fail to get the result. Have added some additional lines to aid debugging.
Copy code
{{#assign 'aDate'}} {{soapXPath request.body '/RealTimePriceDataWebService/reportBean/ReportBean/ParamValue/text()'}} {{/assign}}
			
			Date from xpath : {{aDate}}
			
			Date from xpath plus one day : {{date (parseDate aDate format="yyyy/MM/dd") offset='1 days'}}
			
			Simple date : {{date}}
			Simple now  : {{now}}
			
			Date from xpath plus one day : {{date (parseDate aDate format="yyyy/MM/dd") offset='1 days'}}
However the output that I get for the above is not as expected
Copy code
Date from xpath : 21-Oct-2020
			
			Date from xpath plus one day : 2023-10-18T01:36:39Z
			
			Simple date : 2023-10-17T01:36:39Z
			Simple now  : 2023-10-17T01:36:39Z
			
			Date from xpath plus one day : 2023-10-18T01:36:39Z
The request body is
Copy code
<soapenv:Header/>
   <soapenv:Body>
      <cor:RealTimePriceDataWebService>
         <cor:reportBean>
            <java:ReportBean>
               <java:ParamName>Date</java:ParamName>
               <java:ParamValue>21-Oct-2020</java:ParamValue>
            </java:ReportBean>
         </cor:reportBean>
      </cor:RealTimePriceDataWebService>
   </soapenv:Body>
</soapenv:Envelope>
Instead of doing the offset on the date grabbed from xpath, the code seems to be doing an offset on the current date. May I know what mistake am I doing .
l
Tom already answered here, and I was just coming to the same conclusion. Try something like the following:
Copy code
{{#assign 'aDate'}} {{soapXPath request.body '/RealTimePriceDataWebService/reportBean/ReportBean/ParamValue/text()'}} {{/assign}}

Date from xpath : {{aDate}}

Date from xpath plus one day : {{date (parseDate aDate format="dd-MMM-yyyy") offset='1 days'}}

Simple date : {{date}}
Simple now  : {{now}}

Date from xpath plus one day : {{date (parseDate aDate format="dd-MMM-yyyy") offset='1 days'}}
Should give you the following output:
Copy code
Date from xpath : 21-Oct-2020

Date from xpath plus one day: 2020-10-22T00:00: 00Z

Simple date: 2023-10-17T08: 09:55Z
Simple now: 2023-10-17T08: 09: 55Z

Date from xpath plus one day: 2020-10-22T00: 00:00Z
👍 1
r
That is a big oversight from me that I shd have seen easily. My bad. I should take some rest. Thanks a lot for your valuable time and help.
l
No worries at all. Glad to help 👍