How to change time format when using the time fields?

I am using erpnext v14.33.1, if i am not mistaken:

I am trying to use the time tag in notification mails and it sort of works, but the time is displayed in a very weird way. It should be in the format hh:mm:ss, but it gets something like hh:mm:ss:ms etc. Is this some kind of bug? Or any way how i can fix this?
grafik

And another thing I am trying to figure out, I dont want to open a whole new post for it :slight_smile:

How can I include a “View this content in browser” button for attached documents in notification mails, its possible for general mails with the “Send document web view link in email” button in the system settings, but I want to achieve the same with notification mails and wasnt able to figure it out until now. The link should be in this format: https://erp.domain.com/Sales%20Order/SAL-ORD-2023-00001?format=Standard&key=anykey

If anyone could help me, that would be great. Thank you!!

Hi @TubaApollo,

Please try it custom/client script for it.

frappe.ui.form.on('Your Doctype', {
  your_field: function(frm) {
    var time_str = frm.doc.your_field; // Replace "your_field" with your actual field name
    var formatted_time = moment(time_str, ["HH:mm:ss"]).format("HH:mm:ss"); // Replace "HH:mm:ss" with your desired format

    frm.set_value('your_field', formatted_time); // Replace "your_field" with your actual field name
  }
});

Thank You!

1 Like

Hey, first of all, thank you for your help.

Sadly i cant get it to work, that’s how it currently looks:

Since i wasnt completely sure i tried frm.set_value(‘doc.time’, formatted_time); and frm.set_value(‘time’, formatted_time);, but both hasnt changed anything to the time format. I am probably doing something wrong, any idea? :slight_smile:

your_field: function(frm) {

Replace your_field with your actual field name
Also try storing the value in a separate field (perhaps a virtual docfield) or try logging to the console.
If your case is purely for print format/notification then just format the time through Jinja instead.

Oh, i am blind, and yes, i only need it for notifications, i will try it with jinja templating

Should be something like

{{ doc.time.strftime('%H:%M:%S') }}

Not tested.

I achieved what i wanted with: {{ frappe.format(doc.time, {"fieldtype":"Time"}) }} Calling "strftime" works in document preview but failed using printview and PDF generation. ¡ Issue #12232 ¡ frappe/frappe ¡ GitHub

strftime doesnt seem to work.

Thank you :slight_smile:

Any idea how I can link documents in notification mails? Like I explained in the post? Would be great!

https://docs.erpnext.com/docs/v13/user/manual/en/setting-up/articles/include-document-link-in-notification-email

I tried this: “<a href="{{frappe.utils.get_url_to_form(doc.doctype, doc.name)}}">{{doc.name}}</a>”, but it will link to the document without a key, so you cant access it without being logged in