Hi All,
I would like to share some information on one of the workaround which I have tried recently.
Requirement: In the standard system when worker field lookup is open on the Correction screen. The filter option on lookup is disabled. There was a request to enable these filters.
Path: Inventory Management -> Periodic tasks -> Quality Management -> Corrections.

When I was analyzing the code to identify how the filters where disable I found that the InventTestCorrection form has a lookup reference method created for the CorrectionResponsibleWorker field.
This method is calling HCMWorkerlookup::newOnlyActiveEmployeesWithinCompany method and in this method, the filter option enable disable logic is handled.



Solution: I have used Disposable Context and COC combination to enable filters on lookup.
Created Disposable Class: TestContext
class TestContext implements System.IDisposable
{
static TestContext instance;
public boolean eventValid;
public void new()
{
if(instance)
{
throw error("Nesting of TestContext is not supported");
}
instance = this;
}
public void dispose()
{
instance = null;
}
static public TestContext current()
{
return instance;
}
}
Consumed Test Context class with COC method.
Class: TestHcmWorkerLookup_Extension
[ExtensionOf(classstr(HcmWorkerLookup))]
final class TestHcmWorkerLookup_Extension
{
public static HcmWorkerLookup newOnlyActiveEmployeesWithinCompany()
{
TestContext context = TestContext::current();
HcmWorkerLookup hcmWorkerLookup = next newOnlyActiveEmployeesWithinCompany();
if(context && context.eventValid)
{
hcmWorkerLookup = TestHcmWorkerLookup::newOnlyActiveEmployeesWithinCompany();
}
return hcmWorkerLookup;
}
}
Created a new child class extending the HCMWorkerLookup class method.
Class: TestHcmWorkerLookup
class TestHcmWorkerLookup extends HcmWorkerLookup
{
public static HcmWorkerLookup newOnlyActiveEmployeesWithinCompany()
{
HcmWorkerLookup hcmWorkerLookup = new HcmWorkerLookup(true, true, true, false, false, true, false, false, false, false);
return hcmWorkerLookup;
}
}
Created a calling method COC to set my Context variable value.
Class: TestInventTestCorrection_Extension
[ExtensionOf(formdatafieldstr(InventTestCorrection, InventTestCorrection,CorrectionResponsibleWorker))]
final class TestInventTestCorrection_Extension
{
public Common lookupReference(FormReferenceControl _formReferenceControl)
{
Common lookupRef;
using(TestContext context = new TestContext())
{
context.eventValid = true;
lookupRef = next lookupReference(_formReferenceControl);
}
return lookupRef;
}
}
I am now able to see the filters option enabled on the lookup.
Result:

Please share your suggestion on other ways through which such a requirement can be handled.