cancel
Showing results for 
Search instead for 
Did you mean: 

Adding Months via Expression

David_Dufresne
Confirmed Champ
Confirmed Champ

is there a way to get the "AddMonths" expression to recognize what month it is and actually add the correct number of days?  trying to get this to fire on last day of month and then update a KW in a Unity form to reflect the next due date (last day of next month) but it just adds 30 days  😞  see image...should be 7/31/22.  every month WF will send out a reminder based off date in Unity form and then it needs to update that KW in the form to the next month and wait til timer fires again

 

0e73cf57e1064ed6b58e6b31c51cacd4

1 ACCEPTED ANSWER

Sean_Killian
Elite Collaborator
Elite Collaborator

I like @Larissa Armand's answer because while the expression is longer, it's clearer what it does:  It computes the 1st of the month, 2 months from now, and then decreases the day by 1 which will get you the last date of next month.  That being said, there's a small problem:  By using Month(%VPropDate) + 2, you get an error in November and December (11 + 2, 12 + 2 = 13th and 14th months which doesn't work):


c5080e18fe5e4aadbfeba8792be52e92


I recommend an expression closer to this:


AddDays(AddMonths(AddDays(%VPropDate;1-Day(%VPropDate));2);-1)


You could replace the %VPropDate with Now(), but this expression preserves the time component of the date, so you'll get the last day of next month at the current time (plus or minus an hour if there's a DST transition one direction or another between the current date and the last day of next month).  If you don't want that, I recommend keeping %VPropDate and adding a Set Property to Expression that sets %VPropDate to this:


Date(Year(Now());Month(Now());Day(Now()))


And then put that Set Property to Expression right before the Set Property to Expression action that calculates the last day of next month.  You could technically put it all into one big expression:


AddDays(AddMonths(AddDays(Date(Year(Now());Month(Now());Day(Now()));1-Day(Date(Year(Now());Month(Now());Day(Now()))));2);-1)


But I consider that near impossible to read.  If you split it into two steps, you can name them something clear like "Put current date into %VPropDate" and "Calculate Last day of Month after %VPropDate" which is easier to understand when you look at the workflow later!

View answer in original post

8 REPLIES 8

David_Dufresne
Confirmed Champ
Confirmed Champ

Thanks for both answers.  this is a bit overwhelming as i'm new to this Expression thing and it's pretty complex to do something seemingly easy!

David_Dufresne
Confirmed Champ
Confirmed Champ

Making progress, I must be missing something.  I setup both Expressions and they appear to work correctly but the KW isnt updating.  any ideas?

this is what I'm doing...can ignore first two Actions :

 

61d82aca00e04e9e8235227b30d13896

 

9cb44948575a43aa90abd884aae1a819

 

 

eebda9fb355b49018171f0dc08877280

Looks like you ought to be close. I would check: 

 

1. Property names match exactly (sometimes a space at the end will be an issue)

2. Property bags match between actions (both use session, both use scoped or both use persistent)

3. Data type on the keyword. If it's a date data type, you might need to take an extra step to format the property output as just the date, where you can see in the expression tester it's giving a date/time result. 

 

If you use on demand diagnostics in the Unity client (file > troubleshooting) and set the workflow level to debug, that should walk through all the steps it's taking and shed some light on the issue.

@Larissa Armand thank you so much 🙂  going to work through your suggestions

Getting started

Find what you came for

We want to make your experience in Hyland Connect as valuable as possible, so we put together some helpful links.