ui-field formula to return current time

  • 2
  • Question
  • Updated 2 years ago
  • Answered
Is there a formula to return the current time in a UI-field?
Photo of Bill Fox

Bill Fox

  • 7,954 Points 5k badge 2x thumb

Posted 2 years ago

  • 2
Photo of Barry Schnell

Barry Schnell, Champion

  • 18,076 Points 10k badge 2x thumb
Hi Bill - If you need the current time at the time the page loads, you can use FORMAT_TIME("hh:mm::ss", NOW()).  However, if you need the current time to constantly be updated while the user is on the page, this would require a javascript solution that updates a field value in the background and then use that field value in the FORMAT_TIME formula function.
Photo of Bill Fox

Bill Fox

  • 7,954 Points 5k badge 2x thumb
Thanks Barry. That worked.  If I am now creating a new row and want to put the results of the time field into another field in the new row.  The ID of the date field is Random6.  I tried to asign:
{{$Model.Add_CR_Add_Task.data.0.Random6}}  or
{{Random6}}

But neither works.  Any suggestions?
Photo of Barry Schnell

Barry Schnell, Champion

  • 18,076 Points 10k badge 2x thumb
Hi Bill - Glad the formula worked.  Need some more information before I can help with the 2nd question:

1) How are you creating the new row?  Is it using the action framework create new row and then uses default values, is it a model that has "create new if none" enabled where the new row is created on page load?

2) Is the field that you are trying to put the result in to a UI-Only field or a SFDC SObject field?  

3) What is the datatype of the field that you are trying to put the new value in to?
Photo of Bill Fox

Bill Fox

  • 7,954 Points 5k badge 2x thumb
The data type is text.
The field is a SFDC Sobject field
I am only using 4 digits from the time field.
Photo of Barry Schnell

Barry Schnell, Champion

  • 18,076 Points 10k badge 2x thumb
Hi Bill -

I think I know what's going on here.

When a new row is created, skuid appears to be applying default values specified in the action configuration BEFORE evaluating the formulas.  This means that your "Random6_Email" field is blank/empty when the default value is applied to Temp_Confirm_Email_Base_c.

Fortunately, there is a solution.  If you remove the default value from the action configuration and instead, add a "row created" event to the Add_CR_Add_Task model, in that event you can set the value of Temp_Confirm_Email_Base_c from Random6_Email.  This approach will work because the row.created event is the last thing to occur during row creation and by this point, all defaults are applied and formulas evaluated.

This does bring up an interesting chicken/egg scenario with the order of default values and formula evaluation.  I think there is something to be said for having Skuid evaluate formulas immediately upon row creation and not wait until the very end.  That said, I'm thinking there is probably good reason why they chose to do it the way that they did.  

For now, let me know if the above approach works for you to at least get your past your current issue.
Photo of Bill Fox

Bill Fox

  • 7,954 Points 5k badge 2x thumb
Using your theory of when they do formulas.  I did an update later in string.
Photo of Barry Schnell

Barry Schnell, Champion

  • 18,076 Points 10k badge 2x thumb
Yep, that approach would work to.  Basically anytime after the create row action is complete, the formula value will be available to use.  I'm going to log another community post to analyze where formula's should be processed when creating new rows.

Edit: Created post at https://community.skuid.com/skuid/topics/evaluate-formula-fields-earlier-in-the-create-new-row-proce...
(Edited)
Photo of Greg Jarrett

Greg Jarrett

  • 3,496 Points 3k badge 2x thumb
A slightly different approach here which we implemented in about 5mins (because we required a constantly counting UTC time clock on a page) was to embed a clock from timeanddate.com which can be embedded in a template component.



This clock keeps ticking over regardless of page load, so our users know exactly what the current UTC time is. A clock can be created here: http://www.timeanddate.com/clocks/free.html and then the iframe code copied into a template on the page.

Or just copy the iframe we created: 
<iframe src="https://freesecure.timeanddate.com/clock/i57odhda/tluk/tct/pct/tt0/tw0/tm1/th1/ta1"; frameborder="0" width="182" height="18" allowTransparency="true"></iframe>
Photo of Bill Fox

Bill Fox

  • 7,954 Points 5k badge 2x thumb
Thanks Greg