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

Notifications

Announcements

No record found.

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 171 Super User 2025 Season 2

#2
#ManoVerse Profile Picture

#ManoVerse 83

#3
Jimmy Passeti Profile Picture

Jimmy Passeti 50 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans