How can I wait for the result of aras.evalMethod when the called Method opens a dialog?
- 8 months ago
Hi Angela,
I was able to get this working by returning the promise from the second method in this example, i.e.:
[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:3afa909f-12ea-4e15-8121-3ed0476bdb26:type=html&text=return%20window.ArasModules.Dialog.confirm%28message%2C%20dialogOptions%29.then%28%0Afunction%28res%29%20%0A%7B%0A%20%20%20%20switch%20%28res%29%20%0A%20%20%20%20%7B%0A%20%20%20%20%20%20%20%20case%20%27ok%27%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20dosomething%28%29%3B%0A%20%20%20%20%20%20%20%20%20%20%20return%20true%3B%0A%20%20%20%20%20%20%20%20default%3A%0A%20%20%20%20%20%20%20%20%20%20%20return%20false%3B%0A%20%20%20%20%7D%0A%7D%29%3B]
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.:
[embed:dc8ab71f-3b98-42d9-b0f6-e21e02a0f8e2:89a4d5e9-d7e9-45a5-acd6-bf288bdb7449:type=text&text=aras.evalMethod%28%22MySecondMethod%22%2C%20document.thisItem%2C%20args%29.then%28%28result%29%20%3D%3E%20%7B%0D%0A%20%20%20%20if%20%28typeof%20result%20%3D%3D%20%22object%22%20%7C%7C%20result%20%3D%3D%3D%20false%29%0D%0A%20%20%20%20%7B%0D%0A%20%20%20%20%20%20%20%20return%3B%0D%0A%20%20%20%20%7D%0D%0A%20%20%20%20%0D%0A%20%20%20%20alert%28result%29%3B%20%2F%2F%20We%20immeditelly%20get%20this%20alert%20after%20the%20Method%20call.%20It%20will%20be%20empty%2C%20as%20the%20dialog%20it%20self%20wasn%C2%B4t%20resolved%20yet.%0D%0A%20%20%20%20%0D%0A%20%20%20%20%2F%2F%C2%A0Other%20code%2C%20e.g.%20hide%20a%20button%0D%0A%20%20%20%20const%20el%3Ddocument.getElementById%28%22myelement%22%29%3B%0D%0A%20%20%20%20el.style.visibility%20%3D%20%22hidden%22%3B%0D%0A%7D%29%0D%0A]
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.