How can I wait for the result of aras.evalMethod when the called Method opens a dialog?

Hi community,

I have a custom button inside Form that leads to a custom Method.
This Method calls a second client Method with aras.evalMethod.
The second Method does a few checks and then opens a "confirm" dialog. User have to press OK or cancel the dialog.

The overall concept works fine, but I cannot get a valid result of the aras.evalMethod call. The second Method shall return the result of the selected dialog option. But the first Method doesn´t wait for the result of the second Method. So my result will be empty / undefined.

First Method

const args = "";
const result = aras.evalMethod("MySecondMethod", document.thisItem, args);
if (typeof result == "object" || result === false)
{
    return;
}

alert(result); // We immeditelly get this alert after the Method call. It will be empty, as the dialog it self wasn´t resolved yet.

// Other code, e.g. hide a button
const el=document.getElementById("myelement");
el.style.visibility = "hidden";

Second Method

[...]
window.ArasModules.Dialog.confirm(message, dialogOptions).then(
function(res) 
{
    switch (res) 
    {
        case 'ok':
            dosomething();
           return true;
        default:
           return false;
    }
});

I tried using promises and async/await. But so far aras.evalMethod never waited for anything. 

I could merge the two Methods, but currently the second Method is called from multiple contexts. So this is something I want to avoid if possible.

Does anyone has an idea that could work to improve the situation?

Thanks!

Angela

Parents
  • Hi Angela,

    I was able to get this working by returning the promise from the second method in this example, i.e.:

    return window.ArasModules.Dialog.confirm(message, dialogOptions).then(
    function(res) 
    {
        switch (res) 
        {
            case 'ok':
                dosomething();
               return true;
            default:
               return false;
        }
    });

    I could then handle the result of this promise in the first method by adding a `.then` statement to the aras.evalMethod call, i.e.:

    aras.evalMethod("MySecondMethod", document.thisItem, args).then((result) => {
        if (typeof result == "object" || result === false)
        {
            return;
        }
        
        alert(result); // We immeditelly get this alert after the Method call. It will be empty, as the dialog it self wasn´t resolved yet.
        
        // Other code, e.g. hide a button
        const el=document.getElementById("myelement");
        el.style.visibility = "hidden";
    })
    

    This isn't a perfect solution in that it does require changing the second method to return a promise which may interfere with how it's being used elsewhere. Let me know if this works for your use case though. 

  • Hi Chris,

    this worked perfectly!!! I did tons of tests with promises, but I never came to the idea of just returning the whole window itself.

    Thanks for the fast help! It saved me a lot of work :). 

Reply Children
No Data