Best way to format data of child template date/time field?

  • 1
  • Question
  • Updated 1 year ago
  • Answered
I need to display a child's lastmodifieddate. I know a couple ways to accomplish this, like creating a saleforce calc field, but before I go to that trouble, I was wondering if anyone knew a quick way to format it as mm/dd/yyyy.
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb

Posted 1 year ago

  • 1
Photo of Gregory Smith

Gregory Smith, Employee

  • 304 Points 250 badge 2x thumb
Photo of Poc

Poc

  • 496 Points 250 badge 2x thumb
any update?
Photo of Skuidward Tentacles (Raymond)

Skuidward Tentacles (Raymond), Champion

  • 17,224 Points 10k badge 2x thumb
I think a salesforce formula field is probably your easiest most proven option.
Photo of Poc

Poc

  • 496 Points 250 badge 2x thumb
it's sad to hear that.
I saw some posts that we can put a snippet which can be invoked by clicking.
I believe if we can trigger the snippet on load. this formatting problem should be solved without a formula field supporting.
Photo of Mark DeSimone

Mark DeSimone, Official Rep

  • 11,040 Points 10k badge 2x thumb
There are lots of things you can do with UI-only formula fields that may be relevant. I've been trying to make use of the MODEL_LOOKUP function on an Account model that grabs data from a separate Contact model. In my case, the formula looks like this: MODEL_LOOKUP("Con","LastModifiedDate","AccountId",{{Id}}). The UI-only field is set up to output as Datetime, but could also be set up as date; either way, this looks to format the UTC code in the more friendly date or date/time format. (Read more here: https://docs.skuid.com/latest/en/skuid/models/ui-only-models-fields.html?highlight=MODEL_LOOKUP)

If you're specifically talking about a child relationship loaded into a parent model (like, for example an Account model with a child relationship on Contacts), this may not get you 100% of the way there. Still, I wanted to share the ideas.

Depending on your specific needs, it might be worth setting up a separate model on the child object and pulling in the relevant fields you're wanting. You could then refer to the model and its fields just about anywhere, using merge syntax.
(Edited)
Photo of Poc

Poc

  • 496 Points 250 badge 2x thumb
Hi, thanks for your guide.
One quick question. 
In my special case, is there any way to pass the children's field value into the snippet.
I tried three kinds of invocations. None of them works.

skuid.snippet.getSnippet('myMEthod')(Status__c)
skuid.snippet.getSnippet('myMEthod')({{Status__c}})
skuid.snippet.getSnippet('myMEthod')({{{Status__c}}})
Photo of Mark DeSimone

Mark DeSimone, Official Rep

  • 11,040 Points 10k badge 2x thumb
Hi Poc, my recommendation would be to preview your page, open the console, and use the command skuid.model.map() to view the raw data in your models. You can then click around and follow the hierarchy to drill down to the model and field relationships you're after. That should give you an idea of how you might refer to them with merge syntax. 
Photo of Poc

Poc

  • 496 Points 250 badge 2x thumb
Hi Mark, thanks for giving me this helpful debugging skill.
However, what I need is the current field value of the current table row.
Any idea to fetch the current field value inside the template field?
thanks

Photo of Gregory Smith

Gregory Smith, Employee

  • 304 Points 250 badge 2x thumb
Can you do something like this? (changing the Owner.CreatedDate to relevant field)


var field = arguments[0],
$ = skuid.$;

var value = new Date(field.row.Owner.CreatedDate);
value = value.toLocaleDateString("en-US")

skuid.ui.fieldRenderers[field.metadata.displaytype][field.mode](field,value);