Skip to main content

Notifications

Microsoft Dynamics CRM (Archived)

Create button that open accounts

Posted on by 760

Hi, 

I wanted to add a button in the form that opens the account entity but my code is not working

<html>
<body>

<input type="text" >
<button onclick="open()">View</button>

<script>

function open()
{
Xrm.Utility.openEntityForm("account");
}

</script>

</html>

*This post is locked for comments

  • Suggested answer
    gdas Profile Picture
    gdas 50,085 on at
    RE: Create button that open accounts

    Hi Jane ,

    Try with this -

    <html>

    <body>
        <input type="text">
        <button onclick="OpenNewWindowEntityForm()">View</button>
        <script>
            function OpenNewWindowEntityForm() {
                var windowOptions = {
                    openInNewWindow: false // You can open in a new window . False means its just redrect to new form
                };
                var parameters = {}; // You can pass parameter also
                // parameters["name"] = Xrm.Page.getAttribute("name").getValue(); // pass parameter getting from current account attribute
                // parameters["accountnumber"] = Xrm.Page.getAttribute("accountnumber").getValue();// pass parameter getting from current account attribute
                window.parent.Xrm.Utility.openEntityForm("account", null, parameters, windowOptions); // Open new creation form
            }
        </script>
    </html>


  • Suggested answer
    Abby Kong Profile Picture
    Abby Kong 6 on at
    RE: Create button that open accounts

    Hi Jane,

    As Mahender and Wei pointed out, you need to add parent to access Xrm.Utility from web resource.

    Other than that, I think you've got something a little tricky here. I tried to test your code, after clicking the button the whole web resource disappear and open() function is never called.

    After further inspecting DOM, all content under web resource (including other text, label etc) is flushed out like this documentempty.png, once the button is clicked, same as in Chrome and Firefox. Suspected the open function get called is document.open() instead of open() in the code, I changed the function name and it started working. Please see the part changed highlighted:

    <html>
    <head>
        <meta>
        <meta>
    </head>
    <body style='word-wrap: break-word;'>
        <button type="button" onclick="openaccount()">View</button>
        <script type="text/javascript"> function openaccount() { parent.Xrm.Utility.openEntityForm("account"); } </script>
    </body>
    </html>

    ----------------------------------------------------------------------------------------
    Check here for parameters and samples for Xrm.Utility.openEntityForm.


    ----------------------------------------------------------------------------------------
    Also, for best practice and avoid this kind of problem, you can try to start using namespace in js code and extract them into separate js file for code reusability, like this:

    var myAbcOrg = {
    foo: function() {
    }
    };
    
    //call with
    myAbcOrg.foo();
    
    

    Regards,

    Abby

  • Suggested answer
    Alex Fun Wei Jie Profile Picture
    Alex Fun Wei Jie 33,626 on at
    RE: Create button that open accounts

    Hi,

    try,

    window.parent.Xrm.Utility.openEntityForm("account");

  • Suggested answer
    Mahendar Pal Profile Picture
    Mahendar Pal 45,095 on at
    RE: Create button that open accounts

    Hello,

    Try

    parent.Xrm.Utility.openEntityForm("account");

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!

Community AMA December 12th

Join us as we continue to demystify the Dynamics 365 Contact Center

Leaderboard

#1
André Arnaud de Calavon Profile Picture

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

#2
Martin Dráb Profile Picture

Martin Dráb 230,188 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans