Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM forum
Suggested answer

Javascript not working on Dynamics CRM

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

Categories:
  • Suggested answer
    Charles Abi Khirs Profile Picture
    Charles Abi Khirs 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
    Sri College 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
    necsa 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
    Clofly 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
    Pawar Pravin 5,227 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

Anton Venter – Community Spotlight

Kudos to our October Community Star of the month!

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Dynamics 365 Community Newsletter - September 2024

Check out the latest community news

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,556 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,625 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans