Skip to main content

Notifications

Customer experience | Sales, Customer Insights,...
Suggested answer

Setting MM/dd date with Java

(0) ShareShare
ReportReport
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 Super User 2024 Season 1 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

News and Announcements

Announcing Category Subscriptions!

Quick Links

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Verified Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,359 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,370 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans