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

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Answered

Short Month and Short Year from Date/Time field using JS

(0) ShareShare
ReportReport
Posted on by 112

Hello experts,

I am going around in circles attempting to create a concatenated column derived from a date/time field.

The code I am using is as follows:

------------------------------------------------

function onChange_dov()
{
var objdate = Xrm.Page.getAttribute("rst_asset_dov").getValue();
if (objdate != null)
{
var year = objdate.toLocaleDateString('en', {year: '2-digit'});
var month = objdate.toLocaleDateString('en', {month: '2-digit'});

Xrm.Page.getAttribute("rst_asset_dov_col").setValue((month + "/" + year));
Xrm.Page.getAttribute("rst_asset_dov_col").setSubmitMode('always');
}
}

----------------------------------------------------

The error I get is telling me the setValue is null:

----------------------------------------------------

One of the scripts for this record has caused an error. For more details, download the log file.

Cannot read properties of null (reading 'setValue')
Session Id: 070e3b8e-8f6b-47a6-8c47-bedc43eed22c
Correlation Id: 35996f97-9348-4bfc-a4d0-ec1a375d99c6
Event Name: onchange
Web Resource Name: rst_asset_dov_calc
Solution Name: ActivePublisher Name: DefaultPublisherSCFMCRM
Time: Fri Feb 11 2022 09:56:50 GMT+0800 (Australian Western Standard Time)
Download Log File
OK
-------------------------------------------------------

Where I test the code and variables and output using objdate = new Date();, there is no issue, it presents 02/22 as I would expect.

Any suggestions would be greatly appreciated.

Thank you in advance,

Jayden.

I have the same question (0)
  • JaydenPerez17 Profile Picture
    112 on at
    RE: Short Month and Short Year from Date/Time field using JS

    Disregard Guido,

    I have answered my own question.

    Thanks again for your help.

    Jayden.

  • JaydenPerez17 Profile Picture
    112 on at
    RE: Short Month and Short Year from Date/Time field using JS

    Hi Guido,

    That is spot on, it ultimately required the field being present on the form in order to apply.

    I dont necessarily want this field to be visible, can it be hidden and still usable?

    Thank you for your assistance,

    Jayden.

  • Verified answer
    Guido Preite Profile Picture
    54,084 Moderator on at
    RE: Short Month and Short Year from Date/Time field using JS

    the error message you are receiving usually means the field is not on the form (in your case the one called rst_asset_dov_col)

    I would double check if the field is present on the form first

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Daniyal Khaleel Profile Picture

Daniyal Khaleel 195

#2
Rishabh Kanaskar Profile Picture

Rishabh Kanaskar 116

#3
Tom_Gioielli Profile Picture

Tom_Gioielli 71 Super User 2025 Season 2

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans