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

showDialogProcess: Cancel / Finish buttons not working properly #8

Closed herr-mueller closed 6 years ago

herr-mueller commented 6 years ago

Hi there,

I'm a big fan of alert.js, but i ran into an issue implementing showDialogProcess function in our environment (V8.2). The Cancel / Finish buttons are not working as expected. In Chrome this buttons do nothing. You can only click the "x" button for closing the dialog, but then the callback function does not get triggered.

In Internet Explorer the Cancel / Finish buttons will close the whole tab or window, if you've only got one tab open.

What can I do?

BR, Joe

PaulNieuwelaar commented 6 years ago

Hi Joe,

I've just done a few tests on my side against CRM v8.2 and also v9.0 using v2.1 of Alert.js and the dialog callbacks seem to be executing correctly in both, using IE and Chrome.

Can you please let me know which versions of IE/Chrome you're using, which version of Alert.js you're using, are you CRM online or on-prem, and finally can you share the snippet of code to call showDialogProcess, including the callback?

Thanks! Paul

herr-mueller commented 6 years ago

Hi Paul,

I am running currently Chrome Version 63.0.3239.108, Alert.js-Version is 2.1, CRM is online.

The showDialogProcess is triggered with the following function

self.showDialogProcess = function (processId) {

  Alert.showDialogProcess(processId, 'prefix_customer_project', getRecordId(), function ()
    {
     Xrm.Page.data.refresh();
     });
}

The dialogURL-Parameter which is called is https://crm.crm4.dynamics.com/cs/dialog/rundialog.aspx?DialogId=%7b2cd6bc96-becd-436b-82e7-4d4a2ee1258d%7d&EntityName=prefix_customer_project&ObjectId=8C2E32BB-D5B3-E711-80F4-3863BB345A68

I don't know, whats the reason why 😞

BR, Joe

PaulNieuwelaar commented 6 years ago

Hi Joe,

The way the dialog callbacks work in Alert.js is that it overwrites the CRM 'closeWindow()' function, which gets called within the Finish/Cancel functions on a dialog. Without overwriting this, it would try to close the whole window/tab like you're seeing in IE. This makes me think the closeWindow function is not getting overwritten correctly for you.

Are you able to check the Alert.js code to make sure it's setting the callback correctly? Or add "debugger;" in where it overwrites the callback to make sure it's all being set and executed correctly. When you click Finish or Cancel it should be calling into this logic rather than trying to execute the default closeWindow logic. I've added 3 debuggers into the below snippet, which should hit 2 during the initial showDialogProcess call, and the final debugger should be hit when you finish/cancel the dialog. At each stage you should be able to see if there's any problems with the code etc (you'll need the F12 dev tools console open).

    var $frame = Alert.$("#alertJs-iFrame");
    debugger;
    $frame.load(function () {
        debugger;
        try {
            // Override the CRM closeWindow function (unsupported)
            var frameDoc = $frame[0].contentWindow;
            frameDoc.closeWindow = function () {
                debugger;
                // Fire the callback and close
                Alert.hide();
                if (callback) { callback(); }
            }
        } catch (e) { }
    });

Sorry if I'm not much help, it's hard to know exactly what the issue might be since it's working fine for me in IE and Chrome on CRM 8.2/9.0.

Let me know if you're able to make any progress.

Kind Regards, Paul

OMoeserITVT commented 6 years ago

Hi Paul,

I am having the same issue on IE 11.0.9600.18861 and CRM Version 8.2.1.342. I tried your method with the debuggers. The first one was called but the second and third didn't. It seems that the override section doesn't get called.

Kind Regards, Oliver

PaulNieuwelaar commented 6 years ago

Hi Oliver,

In the first debugger, does the $frame object contain any elements? You could add alert($frame.length); just to confirm it. Sounds like it's not binding the load event properly.

Cheers, Paul

OMoeserITVT commented 6 years ago

Hi Paul,

the $frame object does contain one element. Do you need specific informations of this element?

Kind Regards, Oliver

herr-mueller commented 6 years ago

Hello Paul,

I still have got this issue. I set the debuggers as you said and I can confirm Olivers observation, that at the first debugger, the $frame contains one element. But if I want to go further, I think the function does not step into the $frame.load function, as the second debugger is not called.

Cheers, Joe

PaulNieuwelaar commented 6 years ago

Hi guys,

Not sure why the load event isn't being bound for you. I've tested this on different computers, using different browsers, and different CRM versions, and I haven't been able to reproduce the issue you're experiencing.

Could you try with either of these alternative methods for setting the onload event, and see if either is getting fired:

$frame.on("load", function () {
   // ...
});
$frame[0].contentWindow.onload = function () {
   // ...
}

Failing that, if this issue is unique to your CRM environments, would it be possible for me to get a login to your environments so I can attempt to reproduce this myself?

Cheers, Paul

OMoeserITVT commented 6 years ago

Hi Paul,

I've tried your suggestions but it didn't work. It didn't step into any of the other onload events.

Kind Regards, Oliver

alex188888 commented 6 years ago

does anyone have a solution for that i have the same problem my users are unable to close the dialog box and the Finish button doesn't work at all

PaulNieuwelaar commented 6 years ago

Hi Alex, unfortunately I haven't been able to reproduce this issue in any of my environments, with any browser. If you're able to test this on different orgs, different browsers, or different users, and are able to narrow down what might be the cause, that would be a great help in solving this issue. Cheers, Paul

alex188888 commented 6 years ago

Hi Paul, My base language is not English could it be the reason? alex :)

On Mon, May 28, 2018 at 10:52 PM, Paul Nieuwelaar notifications@github.com wrote:

Hi Alex, unfortunately I haven't been able to reproduce this issue in any of my environments, with any browser. If you're able to test this on different orgs, different browsers, or different users, and are able to narrow down what might be the cause, that would be a great help in solving this issue. Cheers, Paul

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/PaulNieuwelaar/alertjs/issues/8#issuecomment-392594060, or mute the thread https://github.com/notifications/unsubscribe-auth/Al3kpcHkx3Bz3SmXbt6RBFFv_h1wjyTtks5t3FV2gaJpZM4REQta .

alex188888 commented 6 years ago

@PaulNieuwelaar

actually i found the problem and i fixed it but now I have another one I'm not sure you would be able to help me. I will try:

I created custom ribbon button using in ribbon workbench which pop-up a dialog box using Alert.js (by followeing this guide LINK). now from some reason the button Works only once per form load. so if the user enter the form for the first time clicks on the button he sees the pop up then he decided to close it when he click on the button next time the pop-up will not show and in order to pop up the window he needs to refresh the page.

Any ideas for why this happens?

herr-mueller commented 6 years ago

Hi Alex,

could you please share your fix for this problem?

BR, Joe Am 29. Mai 2018, 20:13 +0200 schrieb alex188888 notifications@github.com:

@PaulNieuwelaar actually i found the problem and i fixed it but now I have another one I'm not sure you would be able to help me. I will try: I created custom ribbon button using in ribbon workbench which pop-up a dialog box using Alert.js (by followeing this guide LINK). now from some reason the button Works only once per form load. so if the user enter the form for the first time clicks on the button he sees the pop up then he decided to close it when he click on the button next time the pop-up will not show and in order to pop up the window he needs to refresh the page. Any ideas for why this happens? — You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.

alex188888 commented 6 years ago

In my case there was a spelling error in the function.

On Tue, May 29, 2018 at 9:20 PM, herr-mueller notifications@github.com wrote:

Hi Alex,

could you please share your fix for this problem?

BR, Joe Am 29. Mai 2018, 20:13 +0200 schrieb alex188888 <notifications@github.com

: @PaulNieuwelaar actually i found the problem and i fixed it but now I have another one I'm not sure you would be able to help me. I will try: I created custom ribbon button using in ribbon workbench which pop-up a dialog box using Alert.js (by followeing this guide LINK). now from some reason the button Works only once per form load. so if the user enter the form for the first time clicks on the button he sees the pop up then he decided to close it when he click on the button next time the pop-up will not show and in order to pop up the window he needs to refresh the page. Any ideas for why this happens? — You are receiving this because you authored the thread.

Reply to this email directly, view it on GitHub, or mute the thread.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/PaulNieuwelaar/alertjs/issues/8#issuecomment-392883067, or mute the thread https://github.com/notifications/unsubscribe-auth/Al3kpVJgv47wZTsXrAHrfw0yKWvaKOuxks5t3ZF9gaJpZM4REQta .

PaulNieuwelaar commented 6 years ago

Hi Alex,

Great to hear you figured out your issue with the dialog not closing.

Regarding your other issue where the alerts aren't being displayed on the second attempt, I've done a quick test and can't seem to reproduce the issue you're describing.

Could you please create a new issue to keep these 2 issues separate, and provide a little bit more detail about how you're calling the alerts, including code snippets, and any info about your environment/browser, and your web resource set up (e.g. if ribbon/form scripts are all in one file etc).

Cheers, Paul

PaulNieuwelaar commented 6 years ago

Hi Joe,

I assume you're still experiencing this issue in your environment?

I'd like to figure this one out.

Have you been able to reproduce this in any other CRM environments? And is it an issue for all users?

I've been unable to reproduce this issue in any of my environments, using any browser or user, so it'd be great to find out any details that will help me reproduce this. E.g. if I can get access into a sandbox instance where you're also having this issue.

Hoping we can solve this issue once and for all.

Cheers, Paul

magnusnet commented 6 years ago

HI Paul!

I'm also having this issue! I think the issue comes from the Javascript being called from a Ribbon.

here's my simple code: ` function openQuickCreateCase() {

    // get the Alert script
    var httpRequest = new XMLHttpRequest();
    httpRequest.open("GET", Xrm.Page.context.getClientUrl() + "/webresources/mag_/js/alert.js", false);
    httpRequest.send(null);
    eval(httpRequest.responseText);
    Alert.show("Text", [new Alert.Button("OK", null, true)], "WARNING", 500, 200);

}`

This works perfectly when used on "Onload" of a form.

But, if I call the JS from a button, then clicking "OK" will not work. I was initially trying to have an "OK" & "Cancel" choice but none of them where working so I tried a piece of code working somewhere else and it's not working either.

image

image

Hope this helps you find the bug :) I tested on Chrome and IE and same result, OK button is K.O. and the cross on the top right works.

PaulNieuwelaar commented 6 years ago

Hi, the alert.js web resource should be loaded into the ribbon using an OOTB custom javascript action, where the function name is isNan, rather than loading it in dynamically. See the documentation for examples of this: https://github.com/PaulNieuwelaar/alertjs/wiki/Documentation-v3.0#installation--usage

For views, add a "JavaScript Function Action" to the "Command Actions" for your button command, calling the alert.js web resource, where the function is "isNaN" (without quotes). Using the Ribbon Workbench to edit the command is recommended.

image

Let me know if doing that works any differently.

Cheers, Paul

magnusnet commented 6 years ago

Thanks for your quick feedback!

I did as you suggested and added the JS Function Action: image

I guess I need to remove the dynamic loading (which I did) but I also guess I need to refer to the alert.js web resource from my custom javascript action I'm sadly not very knowledgeable on JS so i'm not sure how I can achieve this call?

I tried wit this code (commented everything but the Alert.show): ` function openQuickCreateCase() {

    // get the Alert script
    /*var httpRequest = new XMLHttpRequest();
    httpRequest.open("GET", Xrm.Page.context.getClientUrl() + "/webresources/mag_/js/alert.js", false);
    httpRequest.send(null);
    eval(httpRequest.responseText);*/

    Alert.show("Text", [new Alert.Button("OK", null, true)], "WARNING", 500, 200);

}`

And the result is not so nice: image

Thanks in advance!

PaulNieuwelaar commented 6 years ago

Hi, you're missing the second "message" parameter in the Alert.show function.

E.g. should be something like: Alert.show("Text", "Sub text", [new Alert.Button("OK", null, true)], "WARNING", 500, 200);

https://github.com/PaulNieuwelaar/alertjs/wiki/Documentation#alertshow

magnusnet commented 6 years ago

This worked and now it's showing perfectly!

image

Yet I'm back to the initial issue, clicking on "OK" or the X mark (X worked before) will not close the window :(

PaulNieuwelaar commented 6 years ago

Hi, are there any other jQuery resources being loaded onto the form/ribbon? Sometimes these can conflict with the Alert.js code, causing issues similar to this.

If this is the case, then v3.0 should resolve this, if you wanted to try upgrading (however note that v3.0 is trial only). Otherwise try removing the conflicting jQuery reference.

Hope that helps Paul

magnusnet commented 6 years ago

Hello,

Your assumption was right, I tried disabling the OnLoad functions from the msdyn_customerasset form and the OOTB CustomerAssetLibrary is causing issues.

image

Here's the code of the library in case it interests you: https://pastebin.com/8Wtk07wZ

I guess I wont be able to make it work unless I disable the code from said library (or try with version 3.0 as you suggested)?

Regards

PaulNieuwelaar commented 6 years ago

Hi, the fix in v3.0 is basically changing this line: Alert._jQuery = window.jQuery ? window.$ : parent.$; to this: Alert._jQuery = top.jQuery || window.jQuery || parent.jQuery;

You could try updating that in the v2.1 code, to see if it fixes it for you.

Otherwise, you can always try with the v3.0 solution and roll it back to v2.1 if it doesn't work.

magnusnet commented 6 years ago

You, sir, are the best.

Your fix worked like a charm! Thanks a lot for your time and patience!