Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics CRM (Archived)

JavaScript XRM control

(1) ShareShare
ReportReport
Posted on by 902

Hi,

I have found this issue recently that if we don't fill value or not use field in form than this field attribute is not found.

Example :

Birthday Field (This field is in form)

Birthday Field ="26=07-2018" then we got value using this method : Xrm.Page.getAttribute('birthdate').getValue();

But

Birthday Field = "" then we got error like this parameter not found using following code :  Xrm.Page.getAttribute('birthdate').getValue() ;

also getting same issue when Set value in field. We didn't get control so How can we set value in empty field ?.

Few days ago we used same function and got null value if we don't fill value. 

Please let me know if you have any suggestion.

Thanks,

*This post is locked for comments

  • lokesh@dynamisity Profile Picture
    95 on at
    RE: JavaScript XRM control

    Hi keyur,

      

    Please try to use below code 

    function GetSetDateTimeField()
    {
    // Access the field on the form var field = Xrm.Page.getAttribute("birthdate"); // Verify it does exist on the form if (field != null)
    { // Get its field value; Returns the Date Time value var value = field.getValue(); // Set its field value (Current Date and Time) field.setValue(new Date()); // Set its field value to a specific Date and Time (ex. December 25, 2017) field.setValue(new Date("12/25/2017")) } }

    I hope this will help you 

    Please mark verify if it works

    Thanks and Regard

    Lokesh

  • Mahendar Pal Profile Picture
    45,095 on at
    RE: JavaScript XRM control

    In addition to that  before getting value you can simply check if field is avilable on the form or not

    if(Xrm.Page.getAttribute("fieldname")!=null && Xrm.Page.getAttribute("fieldname").getValue()!=null)

    {

    //get value

    }

  • Pawar Pravin  Profile Picture
    5,237 on at
    RE: JavaScript XRM control

    Hi keyur,

    If you try with ternary operator in expression then it will not give any error. It doesn't matter where that field is on a form or not it will return null if it not on form or don't have value.

    For example:

    var bdate = Xrm.Page.getAttribute('birthdate') ? Xrm.Page.getAttribute('birthdate').getValue()  : null;

    Hope this help you.... !

    Regards, Pravin

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

🌸 Community Spring Festival 2025 Challenge Winners! 🌸

Congratulations to all our community participants!

Adis Hodzic – Community Spotlight

We are honored to recognize Adis Hodzic as our May 2025 Community…

Kudos to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Microsoft Dynamics CRM (Archived)

#1
Mohamed Amine Mahmoudi Profile Picture

Mohamed Amine Mahmoudi 83 Super User 2025 Season 1

#2
Community Member Profile Picture

Community Member 52

#3
Victor Onyebuchi Profile Picture

Victor Onyebuchi 6

Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans