PaulNieuwelaar / alertjs

Dialog Builder allows you to create fully customisable dialogs and popups in Dynamics 365.
https://www.magnetismsolutions.com/our-products/alertjs-alert-popup-for-d365
Other
96 stars 38 forks source link

Alert.getCrmWindow() is not working #25

Closed Sagar486 closed 5 years ago

Sagar486 commented 5 years ago

Hi,

I am trying to show a HTML page in Alert.js on Quote form. I am trying to use Alert.getCrmWindow() (even tried with parent.Alert.getCrmWindow())as mentioned in the documentation to get the Xrm object. But this is not working and the resultant window object doesn't have XRM object. Please find the attached screen shot.

alert_error

PaulNieuwelaar commented 5 years ago

Hi, I just tested this in an online trial, and it's working OK for me.

image

Can you please give any more context about how you're using it? What version of CRM, which version of Alert.js, and any other related code?

Thanks, Paul

Sagar486 commented 5 years ago

Hi Paul, We are displaying a HTML page in a web resource on the quote form. We have a button on that html page so that on click of that button, we need to open the html page as an overlay (maximize the page) in an Alert.js using Alert.showWebResource. We need to get the Xrm object in that html page to get some data from the quote form and to do some other stuff. When the html is on the quote form we are just doing "window.parent.Xrm", but when the same html page is opened in Alertjs we are not able to find the xrm object (we can get the xrm object by looping through the window.parent.frames but we don't want to do that).

We downloaded and using Alertjs trail version 3.0.7 just for using getCrmWindow() method and using CRM on prem version 8.2. Please let me know if you need anything else.

Thanks

PaulNieuwelaar commented 5 years ago

Hi, just so I understand, do you have an HTML page embedded into your form, and from within that HTML page, you have a button which called Alert.showWebResource to open another HTML page? If that's the case, in order to get back to the CRM/form context, you'd need to use parent.parent.Alert.getCrmWindow() since the first parent will give you the embedded HTML page.

You can also use window.top.Alert... which will also give you the correct context regardless of how many nested HTML iframes you have.

Hope that helps, Paul

Sagar486 commented 5 years ago

Hi Paul,

You understood it right.

Neither parent.parent.Alert nor window.top.Alert are working. Window.top works only when the html page is opened in a new window or new tab.

Thanks, Sagar

PaulNieuwelaar commented 5 years ago

Hi Sagar,

The 'getCrmWindow' function will return you the window where Alert.js is being loaded in. I'm assuming you are loading the Alert.js file into your first web resource, and then calling Alert.show... directly from there? If this is the case, then getCrmWindow will return you the first iframe/embedded HTML page, since that's where Alert.js is being loaded.

You could try remove the alert.js reference from your first web resource, and load it into the main form libraries, then access the Alert.js reference using parent.Alert from the first web resource. Use that to show the full screen, then use top.Alert.getCrmWindow to get the correct CRM context.

It's a bit of a workaround, but it should work. Let me know how you get on.

Cheers, Paul

Sagar486 commented 5 years ago

Hi Paul, That doesn't work either. Will figure out some other approach. Really appreciate for your inputs on this. Thank you.

Thanks, Sagar