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
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>
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 , 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
Hi,
try,
window.parent.Xrm.Utility.openEntityForm("account");
Hello,
Try
parent.Xrm.Utility.openEntityForm("account");
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,253 Super User 2024 Season 2
Martin Dráb 230,188 Most Valuable Professional
nmaenpaa 101,156