While working with SharePoint / JavaScript modal pop up you might encounter error "cannot read property 'showmodaldialog' of undefined". Here is simple solution for that.
Code Sample:
function OpenDocsDialog(url1) {
var options = {
url: url1,
dialogReturnValueCallback: myDialogCallback
};
SP.UI.ModalDialog.showModalDialog(options); // this line gives error.
}
Solution : We need to load "sp.js" file before calling above code. You can load "sp.js" file with below code sample:
ExecuteOrDelayUntilScriptLoaded(function () { //code }, "sp.js")
Full solutionExample :
function OpenDocsDialog(url1) {
var options = {
url: url1,
dialogReturnValueCallback: myDialogCallback
};
ExecuteOrDelayUntilScriptLoaded(function () {
SP.UI.ModalDialog.showModalDialog(options);
}, "sp.js")
}
Subscribe to:
Post Comments (Atom)
SharePoint Classic Site Retirement: Your Plan to Avoid Last-Minute Chaos
Classic SharePoint has been on borrowed time for years. Microsoft has now put dates on the remaining pieces. Microsoft will disable creation...
-
In last blog we learn how can we enable footer on SharePoint Online Modern Communication site. If you have not gone through that you can use...
-
If you're managing SharePoint Online environments, there's a significant change on the horizon that you need to prepare for. Microso...
-
Issue : Recently, we had a requirement to sync the calendar between shared mailbox outlook and SharePoint Calendar list. We have created 2 f...
This article provides a helpful solution to the SP.UI.ModalDialog.showModalDialog error encountered when working with SharePoint and JavaScript. Explaining how to load sp.js using ExecuteOrDelayUntilScriptLoaded() is a practical way to address script-loading dependencies and ensure the SharePoint modal dialog API is available before it is called.
ReplyDeleteUnderstanding JavaScript execution, asynchronous script loading, and API dependencies is important when developing reliable web applications. Exploring Javascript Online Training in India can help developers strengthen their JavaScript fundamentals and learn practical debugging techniques.
Developers can also benefit from structured learning that covers JavaScript functions, browser APIs, and event-driven programming. A Javascript Online Course in India can provide a foundation for understanding script execution and resolving common issues in web application development.
ReplyDelete