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 :
Microsoft Dynamics CRM (Archived)

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

(0) ShareShare
ReportReport
Posted on by 470

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

I have the same question (0)
  • Verified answer
    Kokulan Profile Picture
    18,054 on at

    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
    };
    }();

  • Verified answer
    gdas Profile Picture
    50,091 Moderator on at

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


  • nickmangioros Profile Picture
    470 on at

    Yes that worked Thanks.

    Now I can start my real scripting

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!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics CRM (Archived)

#1
Varsha deshpande Profile Picture

Varsha deshpande 5

#2
JS-09031509-0 Profile Picture

JS-09031509-0 3

#3
Ciprian  P Profile Picture

Ciprian P 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans