1

I am building a Lightning Quick Action for an object that includes a field of type Time. I would like to prepopulate that Time field with the current time, while allowing the user to make changes. This is a Record Create Quick Action (all declarative).

I added a Predefined Field Value to my Quick Action with the formula TIMENOW():

enter image description here

The documentation for TIMENOW() says

Returns a time value in GMT representing the current moment

The displayed value is based on the organization’s Locale settings.

TIMEVALUE() shows

Returns the local time value without the date

What I'm getting displayed when I launch the Quick Action is definitely GMT, 4 hours ahead of local, despite that my org's default time zone is Pacific Time and my user's configured time zone is Eastern Time:

enter image description here

I've also tried TIMEVALUE(NOW()) and got the same result. The incorrect time persists if the record is actually saved (i.e. the resulting record shows a value 4 hours ahead of local).

Is this broken, or am I misunderstanding what to expect from this functionality? Is there an alternate way to obtain the locale-respecting time value of this moment for display?

  • Can you check timezone in your User record? – Pranay Jaiswal Oct 29 '18 at 20:32
  • My user time zone is Eastern time. – David Reed Oct 29 '18 at 20:33
  • 1
    I am reading here and it seems to return always GMT. The TIMENOW() function returns a value in GMT representing the current time without the date – Jayant Das Oct 29 '18 at 20:34
  • You're right, @JayantDas; I realized I conflated the doc entries for TIMEVALUE() and TIMENOW(). I would expect to see a locale-sensitive value shown regardless, though ("The displayed value is based on the organization’s Locale settings.") – David Reed Oct 29 '18 at 20:45
1

I haven't tried this out myself, but I think this should work for your scenario here.

To start with TIMENOW() always returns the time in GMT.

Returns a time value in GMT representing the current moment. Use this function instead of the NOW function if you only want to track time, without a date.

Additionally, as I see here, it seems you cannot find the User's timezone in formula at all.

There’s no way to determine a user’s time zone in a formula. If all of your users are in the same time zone, you can adjust the time zone difference by adding or subtracting the time difference between the users’ time zone and GMT to your converted values.

So if I had to try, I would use something in my init() function of the component to call an apex aura method to pre-populate the field and in my apex method would do something as below (note - this was just a quick test that I was doing, definitely can be improved)

DateTime dt = Datetime.now();
String formattedStr = dt.format(); // will give the current user's time based on their timezone
String [] allVals = formattedStr.split(' ');
system.debug(allVals[1]);
  • +1 for a clever solution. I am really trying to do this declaratively if at all possible; it's a bit of a last-minute request from business users and I don't want to trigger another testing cycle. – David Reed Oct 29 '18 at 22:12
  • @DavidReed I can understand what you must be going through now :) I will see if I can find something declaratively but in absence of anything, this can work. – Jayant Das Oct 29 '18 at 22:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.