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

display custom modal created dialog via javascript

(0) ShareShare
ReportReport
Posted on by 458

Hi there All, I have created a custom modal that get input, The modal contain a text area and a button.
End-user First Fill text area and then press submit button.
I have created that modal in HTML, and imported the web resource as JS file ! ( is it right? )
Note that I have custom ribbon button( I have customized it via ribbon workbench) and wanna when the ribbon button clicked this modal appear and when submitted, text entered in the modal fill out one filed and be closed.
My First Question is about that how to display this custom HTML?
I have tryed this Html and JS in one File and imported as web resource : 

<!DOCTYPE html><html><head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
/*body {font-family: Arial, Helvetica, sans-serif;}*/
/* The Modal (background) */
.modal {
    display: none; /* Hidden by default */
    position: fixed; /* Stay in place */
    z-index: 10; /* Sit on top */
    padding-top: 100px; /* Location of the box */
    left: 0;
    top: 0;
    width: auto; /* Full width */
    height: auto; /* Full height */
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0, 0, 0); /* Fallback color */
    background-color: rgb(0,0,0,0.4); /* Black w/ opacity */
    text-align: center;


}

.text-area { 

    border: none;
    color: white;
    padding: 20px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 4px 2px;
    cursor: pointer;
     
}

/* Modal Content */
.modal-content {
    background-color: #fefefe;
    margin: auto;
    padding: 20px;
    border: 1px solid #888;
    width: 80%;
    
    -webkit-animation-name: animatetop;
    -webkit-animation-duration: 0.4s;
    animation-name: animatetop;
    animation-duration: 0.4s    
    
    overflow: auto; /* Enable scroll if needed */
    background-color: rgb(0,0,0); /* Fallback color */
    background-color:rgb(211, 211, 211);
    box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);  
    text-align: center;
  
}

.button {
    background-color: rgb(128, 128, 128); 
    border: none;
    color: white;
    padding: 20px;
    text-align: center;
    text-decoration: none;
    display: inline-block;
    font-size: 16px;
    margin: 4px 2px;
    cursor: pointer;
}

/* The Close Button */
.close {
    color: #aaaaaa;
    float: right;
    font-size: 28px;
    font-weight: bold;
}

.close:hover,
.close:focus {
    color: #000;
    text-decoration: none;
    cursor: pointer;
}
</style>
<meta charset="utf-8"></head>
<body>
<!-- The Modal -->
<div class="modal" id="myModal">
  <!-- Modal content -->
  <div class="modal-content">

    <span class="close">×</span>
    <p>Enter the text</p>
   <textarea class="text-area"> </textarea>
   
  <button class="button" id="submitBtn"> submit</button>
  </div>

</div>
<script>
// Get the modal
var modal = document.getElementById('myModal');

 var modalBtn= document.getElementById("submitBtn");

// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];

// When the user clicks the button, open the modal 
function displayOnClick() {
    modal.style.display = "block";
}

// When the user clicks on <span> (x), close the modal
span.onclick = function() {
    modal.style.display = "none";
}

// When the user clicks anywhere outside of the modal, close it
window.onclick = function(event) {
    if (event.target == modal) {
        modal.style.display = "none";
    }
}
</script>
</body></html>


And I call displayOnClick function in command to appear this dialog.


Note that I think the URL does not need for this purpose.
Any help will appreciate.

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Mahendar Pal Profile Picture
    45,095 on at

    Hi,

    You need to have a html webresource where you can put this code and after that you can use openWebResource method from Xrm.Utility, please check this for more details

    msdn.microsoft.com/.../jj602956.aspx

  • Albert_ Profile Picture
    458 on at

    So I add the HTML web resource.

    And a  java script source to the same solution.

    Right?

  • Verified answer
    Mahendar Pal Profile Picture
    45,095 on at

    Yes, your html web resource can have both html and js code.

    You can refer more details about html web resource here: docs.microsoft.com/.../webpage-html-web-resources

  • Albert_ Profile Picture
    458 on at

    Thanks,I will let you know !

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

    Hi Albert ,

    I believe Xrm.Utility is not available in dynamics CRM 2011. I can see you are using Dynamics CRM 2011.

    Alternate way you can use window.open or Xrm.Internal.openDialog . Please note these are not supported options .

    https://www.inogic.com/blog/2014/09/alternative-to-showmodaldialog/

    In addition Xrm.Utility also deprecated in Dynamics 365 now in dynamics 365 you can use Xrm.Navigation.openWebResource instead of Xrm.Utility namespace.

  • Albert_ Profile Picture
    458 on at

    Sir, It display a new web page,

    I wanna just display a modal or dialog, With no browser window.

  • Albert_ Profile Picture
    458 on at

    Thanks for your reply bro.

    Look at the @Mahender reply.

    It worked, but display a webpage.

    Can I just display a modal or dialog?

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

    Hi ,

    Did you tried with -Xrm.Internal.openDialog which I shared previous post . This is not supported but for the time being you can use.

  • Albert_ Profile Picture
    458 on at

    I tried this :

    function displayDialog() {

    // Xrm.Utility.openWebResource("new_simple_modal", null, 250, 250);

    Xrm.Internal.openDialog("/WebResources/new_simple_modal.html", null, null, null, null);

    }

    And Browser return me this ! :

    Xrm.Internal is undefined.

    I call this in ribbon button.

    Whats wrong? The address?

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

    Hi Albert,

    Try with this  - I would suggest first try to give full URL of web resource starting with "http:\\" to make it work.

    function displayDialog() {
    
        // Xrm.Utility.openWebResource("new_simple_modal", null, 250, 250);    
       
        var DialogOption = new Xrm.DialogOptions;
        DialogOption.width = 900;
        DialogOption.height = 620;    
        window.parent.Xrm.Internal.openDialog("/WebResources/new_simple_modal.html", DialogOption, null, null, null); // Make sure you are giving  the correct webrsource path
    
    }


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

#1
SA-08121319-0 Profile Picture

SA-08121319-0 4

#1
Calum MacFarlane Profile Picture

Calum MacFarlane 4

#3
Alex Fun Wei Jie Profile Picture

Alex Fun Wei Jie 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans