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,...
Suggested Answer

Javascript not working on Dynamics CRM

(0) ShareShare
ReportReport
Posted on by 45

CHECK IF A DYNAMICS 365 FIELD IS EMPTY USING JAVASCRIPT

I am using the following code, But it is not working for me.

function AccountOnLoad()

{
if(Xrm.Page.getAttribute("fax").getValue() == null)

{
alert("Fax is empty");
}


}


Thank you

Could you please help anyone..

I have the same question (0)
  • Suggested answer
    Pawar Pravin Profile Picture
    5,237 on at

    Please refer answer suggested in below thread.

    stackoverflow.com/.../36348570

  • Suggested answer
    Clofly Profile Picture
    260 on at

    Hi Partner,

    What the version of Dynamics you are using? Is it CRM2016 or online?

    1. Check whether the function has been loaded to the OnLoad event of Account form.

    pastedimage1614240030900v2.png

    2. Check whether "Enabled" option is checked for your function.

    pastedimage1614239982024v1.png

    3. We should save and publish the form after adding and enabling the script to make the function works.

    4. Check whether Fax field has been added to the Account form.

  • Suggested answer
    necsa Profile Picture
    3,455 on at

    Hi Sree,

    Check first whether the field is on the Form if yes define the field value as a variable and alert the variable value or debug your code.

  • Sri College Profile Picture
    45 on at
    [quote user="cloflyMao"]

    Hi Partner,

    What the version of Dynamics you are using? Is it CRM2016 or online?

    1. Check whether the function has been loaded to the OnLoad event of Account form.

    Image

    2. Check whether "Enabled" option is checked for your function.

    Image

    3. We should save and publish the form after adding and enabling the script to make the function works.

    4. Check whether Fax field has been added to the Account form.

    [/quote]

     I am using version: Version 1710 (9.2.21021.144) online

    i had do the following steps, But still, Javascript is not workifax4.pngfax1.pngfax2.pngng.

    fax3.png

  • Suggested answer
    Charles Abi Khirs Profile Picture
    3,569 on at

    Hello,

    Since you are using D365 v9, Xrm.Page is deprecated and you should use the formcontext as below:

    function AccountOnLoad(executionContext)

    {

    var formContext = executionContext.getFormContext();

    if(formContext.getAttribute("fax").getValue() == null)

    {

     alert("Fax is empty");

    }

    }

    Just make sure that you pass the execution context as first parameter to the function your are calling from the onload event function.

    If it does not work, what is the problem that appears or is there any error in the console (F12)?

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
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 69 Most Valuable Professional

#2
ManoVerse Profile Picture

ManoVerse 60 Super User 2026 Season 1

#3
11manish Profile Picture

11manish 43

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans