Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics CRM (Archived)

Dynamics 365 - Web Resources - Alert not displaying on form OnLoad

Posted on by 460

Hi,

Created a new Web Resource with the following code to display an alert onLoad  of a form.

    var Sdk = window.Sdk || {};

// Define some global variables
  

// Code to run in the form OnLoad event
     this.formOnLoad = function (executionContext) {
            var formContext = executionContext.getFormContext();
                alert('Hello World");
     }
// Code to run in the attribute OnChange event
     this.attributeOnChange = function (executionContext) {
             var formContext = executionContext.getFormContext();
     }

//  Code to run in the form OnSave event
             this.formOnSave = function () {
     }

}).call(Sdk);

All the calls are correctly configured
OnLoad Event:         Sdk.formOnload    &    Pass execution connect as first parameter
No errors when loading form

Any help is greatly appreciated.

Thanks

*This post is locked for comments

  • nickmangioros Profile Picture
    nickmangioros 460 on at
    RE: Dynamics 365 - Web Resources - Alert not displaying on form OnLoad

    Yes that worked Thanks.

    Now I can start my real scripting

  • Verified answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Dynamics 365 - Web Resources - Alert not displaying on form OnLoad

    Hi,

    There is one missing line in addition to quote.  Make sure you provide function name with namespace name ( Sdk.formOnLoad ) in the onload  event handler . Try with this  - 

    // A namespace defined for the sample code
    var Sdk = window.Sdk || {};
    (function () {
        
        // Code to run in the form OnLoad event
        this.formOnLoad = function (executionContext) {
            var formContext = executionContext.getFormContext();
            alert('Hello World');
        }
        // Code to run in the attribute OnChange event 
        this.attributeOnChange = function (executionContext) {
            var formContext = executionContext.getFormContext();
        }
    
        //  Code to run in the form OnSave event 
        this.formOnSave = function () {
        }
    
    }).call(Sdk);


  • Verified answer
    Kokulan Profile Picture
    Kokulan 18,048 on at
    RE: Dynamics 365 - Web Resources - Alert not displaying on form OnLoad

    I think the problem with your script is that the hello world string is not terminated

    alert('Hello World"); -> RED should be single quote.

    I tried the following and it works

    if (typeof (Sdk) === 'undefined') { Sdk = function () { }; }

    Sdk.Customer = function ()
    {
    // Code to run in the form OnLoad event
    var formOnLoad = function(executionContext) {
    //var formContext = executionContext.getFormContext();
    alert('Hello World');
    };
    // Code to run in the attribute OnChange event
    var attributeOnChange = function(executionContext) {
    var formContext = executionContext.getFormContext();
    };

    // Code to run in the form OnSave event
    var formOnSave = function() {
    };


    return {
    FormLoad: formOnLoad,
    AttributeOnChange: attributeOnChange,
    FormOnSave: formOnSave
    };
    }();

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

December Spotlight Star - Muhammad Affan

Congratulations to a top community star!

Top 10 leaders for November!

Congratulations to our November super stars!

Tips for Writing Effective Suggested Answers

Best practices for providing successful forum answers ✍️

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 291,280 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 230,235 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans