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

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..

  • Suggested answer
    Charles Abi Khirs Profile Picture
    3,569 on at
    RE: Javascript not working on Dynamics CRM

    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)?

  • Sri College Profile Picture
    45 on at
    RE: Javascript not working on Dynamics CRM
    [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
    necsa Profile Picture
    3,455 on at
    RE: Javascript not working on Dynamics CRM

    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.

  • Suggested answer
    Clofly Profile Picture
    260 on at
    RE: Javascript not working on Dynamics CRM

    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
    Pawar Pravin  Profile Picture
    5,237 on at
    RE: Javascript not working on Dynamics CRM

    Please refer answer suggested in below thread.

    stackoverflow.com/.../36348570

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 > Customer experience | Sales, Customer Insights, CRM

#1
Daivat Vartak (v-9davar) Profile Picture

Daivat Vartak (v-9d... 225 Super User 2025 Season 1

#2
Muhammad Shahzad Shafique Profile Picture

Muhammad Shahzad Sh... 106

#3
Vahid Ghafarpour Profile Picture

Vahid Ghafarpour 82 Super User 2025 Season 1

Overall leaderboard

Product updates

Dynamics 365 release plans