Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Suggested answer

Setting MM/dd date with Java

Posted on by 10

Hello,

I have been searching through forums trying to find scripting to work for me, but I cannot seems to get anything to work (this could very well be due to my own inexperience/ignorance).

We have a "Policies" entity showing existing policies for our customers. Within this entity there is a "Policy Date" field and a "Policy Date (mm/dd)" field. The "Policy Date" field is a date only field, the "Policy Date (mm/dd)" is a text field. I would like to show the Month and Day from the "Policy Date" field within the "Policy Date (mm/dd)" field, to help with sorting in the "Policies" entity view--we just need to see month and day within the view.

pastedimage1671642776961v1.png

The screenshot shows the "Policy Date" field but once this JS is working, that field will be removed from the view and it will only show the "Policy Date (mm/dd)".

Below is my current script that I have added as a Web Resource.

function newPolicyDate (executionContext){
    var formContext = executionContext.getFormContext();
    var policyDate = formContext.getAttribute("cr1d9_policydate").getValue();
    var month = policyDate.getMonth();
    var day = policyDate.getDate();

    var newPolicyDate = month + "/" + day
   
    if(formContext.getAttribute("cr1d9_policydatemmdd").getValue() == null){
        formContext.getAttribute("cr19d_policydatemmdd").setValue(newPolicyDate)
    }
}

If this could be set up to be automatic, that is preferred (that way I do not have to go into each separate record and update it, or have it done OnChange).
Any help would be very appreciated.

Thanks!
  • Suggested answer
    Abdul Wahab Profile Picture
    Abdul Wahab 12,070 Moderator on at
    RE: Setting MM/dd date with Java

    Hi Lukewarm00,

    What if you can fix old data with the help of

    1. Power automate
    2. Excel online
    3. Console application

    For the new records, it will be handled on 

    1. onload
    2. on create

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,556 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,625 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans