web
You’re offline. This is a read only version of the page.
close
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..

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 73 Super User 2025 Season 2

#2
Gerardo Rentería García Profile Picture

Gerardo Rentería Ga... 43 Most Valuable Professional

#3
Daniyal Khaleel Profile Picture

Daniyal Khaleel 32 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans