1

I am working on an entity view that displays billing records with associated date. This date field needs to be displayed as "Month - Year". Unfortunately, I am not able to find a way to format this date field outside of modifying the entity and even then, I only have the option for date only or date and time.

I have noticed that I can select the field and click on Change Properties. There I have "Web Resource" and Function Name. I have tried creating a web resource with a function that returns some data. Set everything up, saved and published. This function is not even found in dev tools. Only examples that I have for it are dealing with using this method for icons:https://www.c-sharpcorner.com/article/view-customization-with-javascript-in-dynamics-365/

In another example the suggestion is to use calculated fields, but this would cause me to lose date sorting and filtering on the form.

Luc
  • 320
  • 4
  • 11
isokolov
  • 11
  • 3

2 Answers2

1

That view-based JavaScript seems to be to choose an icon. I'm not sure it would allow you to reformat actual data in the view. And if you're looking for assistance with trying to do that, you'd probably get more help if you posted the code.

Besides the JavaScript approach, you might want to think about creating a separate text field to hold the "Month - Year" value. Then you could use a workflow, plugin, or JavaScript to populate it when the datetime field changes.

One of the free workflow tool packages (Jason Lattimer's, Aiden Kaskela's, or Andrew Butenko's) probably has the ability to parse the date so you can format the month and year, and store the string in the separate field. This would be a no-code option.

Alternatively, you could write a plugin to reformat the datetime values and register it on the RetrieveMultiple message of the entity.

I'd probably go with a separate field and an off-the-shelf workflow utility to populate it.

Aron
  • 3,877
  • 3
  • 14
  • 21
  • Hi Aron, honestly I do not have the code to post, since I could not get that function to fire as described above. It does seemed to be for an icon, since it requires icon name and tool tip on the return. Text fields would not work for me since I need date sort and filtering to still work. I was looking to keep the integrity of the date field, yet display a string. Kind of the same way as Telerik grid control – isokolov Oct 09 '19 at 20:28
  • Understood. Perhaps you could display the date field too and/or put the string in the format yyyy-MM to maintain sortability. – Aron Oct 11 '19 at 00:54
0

There are several ways: 1. Setting->Administration->System Setting->Format->Customize, 2. http://prntscr.com/ph42nc, 3. or use on load with js to change date format more on this subject here: How to change date format in JavaScript

EmirSa
  • 11
  • 5
  • #1 and #2 seemed to be the same solution and will change the date format site wide, unless I am missing something. In regards to #3, this is an associated view, that is being used across multiple entities so I would have to add, js lookup to multiple forms, and on load does not have the view loaded yet. Something needs to trigger it later. I will look again and let you know if that is a solution. – isokolov Oct 09 '19 at 20:04
  • Second one is a picture just in case, open your view, and then try to add your js format function here: http://prntscr.com/ph4hk5 – EmirSa Oct 09 '19 at 20:17
  • Yeah, I tried that, as I described up top. I have the web resource added to the parent entity and I can't get that to fire, and I am pretty sure it is just for the icons. – isokolov Oct 09 '19 at 20:24
  • Can you force some on change event to see and console log something to see does the function even fire at all. – EmirSa Oct 09 '19 at 20:28