FormRun.wait(): method is deprecated, what to use instead?
Asked Answered
D

1

5

I am currently working on fixing some BestPractice-Warnings on a bigger project. There i have a few instances where forms are called and are awaited before doing more stuff, this is mostly some dialogs. To await form the following code is used very often:

Object formRun;

//declare args and stuf...
formRun = classfactory.formRunClass(args);
formRun.init();

//call methods on formRun (display,run,etc...)

formRun.wait();

The problem i am facing now is that 'wait()' seems to be deprecated and i don't get how to replace or fix this. I have seen that some devs declared the form as 'Object' to get rid of this warning (didn't work by the way, this will still be detected), but this is a late-bound-call which should also be avoided...

Has anyone else had this issue ? i tried calling this method using the system.reflection namespace but this doesn't look right and is also much more code in x++ than should be needed for such a simple task.

Dialytic answered 8/3, 2019 at 13:29 Comment(0)
S
7

TLDR

I think this is a false positive from the best practice checks. To get rid of the best practice warnings, you can add them to the list of suppressed best practices or add a best practice suppression in code.

Details

In Deprecated APIs (June 2017) it says for the wait method of Object:

Overview

Used to block and wait for an interaction/operation and notify to unblock.

Reason for deprecation

These calls are deprecated for all objects except formRun and it’s derivatives.

Migration notes

Calls to these APIs from formRun or it’s derivatives are allowed. Calls to these APIs from any other object should be removed.

When you do a metadata search for code:"formRun.wait()", you will also get a lot of results (more than 1000 on version 8.0). This is further indication that the method is not deprecated for FormRun.

That said, you may want to take a look at the following link which mentions a formRun.lifecycleHelper() to which event handlers can be added. I haven't personally tried this so far, but it may be applicable to your case.

FormRun.wait, Box and ChangeCompany - a poor cocktail

Siren answered 9/3, 2019 at 14:32 Comment(1)
Then i'll add a suppression in code for theese instances to get rid of this for now. I'll check out the 'lifecycleHelper()' later, i'd prefer solving cases like this without having to supress warnings. suppressing warnings feels wrong and i have a bad feeling this might bite me in the futureDialytic

© 2022 - 2024 — McMap. All rights reserved.