2

Objective: create a List-View Button that writes the date value of the immediately upcoming Monday to a field in the selected record(s)

E.g. if Monday is Dec 5, the expected output for writing a value to that field would be: 12/5/2016

What are some recommended ways to write a "formula" so that regardless at one day in the week, a user clicking the button will achieve the expected output of writing the date of the upcoming Monday to that record?

Where I have gotten so far is this formula which is more for retrieving the text-value of a date, but I need to write a dynamically changing date value that will always be the datevalue of the upcoming Monday.

CASE(MOD( {!CloseDate} - DATE(1900, 1, 6), 7), 0, "Saturday", 1, "Sunday", 2,"Monday", 3, "Tuesday", 4, "Wednesday", 5, "Thursday", 6,"Friday","")

1 Answer 1

3

A quick Google revealed this:

CASE(
MOD(TODAY()  - DATE(1900, 1, 8), 7),
0, TODAY() + 7,
1, TODAY() + 6,
2, TODAY() + 5,
3, TODAY() + 4,
4, TODAY() + 3,
5, TODAY() + 2,
6, TODAY() + 1,
DATE(9999,01,01)
)

that I assume could be refactored a bit and changed for your case to:

CloseDate + CASE(
MOD(CloseDate  - DATE(1900, 1, 8), 7),
0, 7,
1, 6,
2, 5,
3, 4,
4, 3,
5, 2,
6, 1,
0
)

Adding 1 to a date moves it on a day.

3
  • thank you! I was toying around with something similar after I posted this question, but this is a lot more robust. Do you know how I might package this formula into a javascript button expression? Will open it up as a separate question.
    – GPP
    Commented Dec 4, 2016 at 0:47
  • @GPP JavaScript has different building blocks so if you can't find an answer through Googling e.g. stackoverflow.com/questions/4156434/… yes ask a separate question.
    – Keith C
    Commented Dec 4, 2016 at 10:51
  • yep I have been googling the heck out of it, I just don't like the answers. (lol) Seems like it involves way too much code and SFDC's merge functions {!TODAY()} aren't working in here...
    – GPP
    Commented Dec 4, 2016 at 19:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .