01-19-2022 03:46 PM
Hi,
I have a scenario where I am trying to increment a date field by 7 days in loop till it reaches another date value. I see data type as date for the field I am working, still while using plusDays(7) function I am getting error. I couldn’t date.parse() as it’s already a date field. I can’t convert to string as I need to add days to the same field in loop. Does anyone know how to overcome this issue? Please advise.
PFA of screenshot from mapper snap.
Regards,
Amar.
01-20-2022 12:36 PM
May I ask why do you need the loop when you already know the desired date? If you need all of the dates between two dates with step = 7 ( Ex.: 2022.01.01,…08,…15,…22,2021.01.29), than you can achieve this with the following expression:
sl.range(0,(($endDate-$startDate)/86400000)+1).filter(x=>x%7==0).map(y=>$startDate.plusDays(y))
Here is a sample pipeline as well:
Date Range Step 7_2022_01_20.slp (3.8 KB)
I hope you’ll find this helpful.
01-20-2022 03:07 PM
Thanks for your response Bojan.
Scenario is to check first row of the weekof < post_prod_support7. If it’s true I need to add 7 days to weekof and append second row with no change in other columns.
Next is to check second row of the weekof < post_prod_support7. If it’s true I need to add 7 days to weekof and append third row with no change in other columns.
Next is to check third row of the weekof < post_prod_support7. If it’s true I need to add 7 days to weekof and append forth row with no change in other columns.
.
.
.
likewise it has to add records with only change in weekof field value alone, till above condition is false.
I tried the expression you shared earlier and getting a different issue. PFA. Any tip will be helpful.
Regards,
Amar.
01-21-2022 12:48 AM
These are Date types, as we said before, you have to parse them, than do the operations. Try this:
sl.range(0,((Date.parse($post_prod_support7)-Date.parse($weekof))/86400000)+1).filter(x=>x%7==0).map(y=>Date.parse($weekof).plusDays(y).toLocaleDateString())
01-24-2022 10:29 AM
Thanks Bojan for your reply. Here is what I am trying. Filtering as per below condition and trying to add 7 days to weekof field value.
($weekof<$post_prod_support7 && $weekof != null && $weekof != ‘’)
But, I am getting below error when try adding 7 days to weekof. I tried with and without Date.parse($weekof). I am still getting error. Kindly help.
PFA of screen.
Regards,
Amar.
01-24-2022 01:04 PM
Check my original reply, parse the stringified version of the field… Date.parse($weekof.toString).plusDays(7)