I have tried a few things. Can someone tell me why the following does not work?
Hi B,
In this case you need to use the full XML path of the location of you data with the data.extract() function.
For example, let’s assume that I have a string variable (in a date format) “Period_Covered_End_Date” and I need to create a new data mapper field "requestDate" whose value is 1 day less than “Period_Covered_End_Date” field or other words, lest substract 1 day from the “Period_Covered_End_Date” value.
Date calculation like this one works best if you first convert the date in milliseconds (starting point being 01/01/1970)
First I would use the following line to convert the date to milliseconds:
new Date() declares a new date variable and the + simply converts it to milliseconds.
+new Date(data.extract(‘./CUSTOMER/INVOICES/INVOICE/Period_Covered_End_Date’))
Next, I will then substract 24 hours from my date (in milliseconds)
+new Date(data.extract(‘./CUSTOMER/INVOICES/INVOICE/Period_Covered_End_Date’)) - 86400000
The result of the above will be an integer; which I need to covert back to a date format. So as the Date() function only accepts strings as parameter, lets first convert this value to a string and assign it to a variable:
var strtempDate = new Date((+new Date(data.extract(‘./CUSTOMER/INVOICES/INVOICE/Period_Covered_End_Date’)) - 86400000)).toString();
Finally, we then return the value to the data mapper as a string field (in the locale date format):
var strtempDate = new Date((+new Date(data.extract(‘./CUSTOMER/INVOICES/INVOICE/Period_Covered_End_Date’)) - 86400000)).toString();
(new Date(strtempDate)).toLocaleDateString();
The result is in the below screenshot:
Period_Covered_End_Date == 31/08/2015
requestDate == 30 August 2015 (in the locale format. This result can be formatted in any way you desire)
Regards,
Rod