web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
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!
I have the same question (0)
  • Suggested answer
    Abdul Wahab Profile Picture
    12,119 Moderator on at

    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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Nagaraju_Matta Profile Picture

Nagaraju_Matta 121

#2
ManoVerse Profile Picture

ManoVerse 67 Super User 2026 Season 1

#3
Abhilash Warrier Profile Picture

Abhilash Warrier 66 Super User 2026 Season 1

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans