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

Announcements

No record found.

News and Announcements icon
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)
  • Verified answer
    Guido Preite Profile Picture
    54,086 Moderator on at

    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

  • JaydenPerez17 Profile Picture
    112 on at

    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.

  • JaydenPerez17 Profile Picture
    112 on at

    Disregard Guido,

    I have answered my own question.

    Thanks again for your help.

    Jayden.

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Meet the Microsoft Dynamics 365 Contact Center Champions

We are thrilled to have these Champions in our Community!

Congratulations to the April Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
ManoVerse Profile Picture

ManoVerse 91 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 72

#3
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans