web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Supply chain | Supply Chain Management, Commerce
Unanswered

Extensibility using System.IDisposable class and COC combination

(1) ShareShare
ReportReport
Posted on by 84

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.

pastedimage1596017041343v2.png

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.

pastedimage1596017588823v3.png

pastedimage1596017859341v4.png

pastedimage1596017901571v5.png

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: 

pastedimage1596018868240v7.png

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

I have the same question (0)
  • Martin Dráb Profile Picture
    237,876 Most Valuable Professional on at

    Please make sure that you post source code with indentation next time - it's difficult to read without it. The extra spaces between lines don't help either. You can either use Insert > Insert Code (in the rich formatting view) or use 'pre' element directly in HTML.

    By the way, the whole thing looks more like a blog post than a question in a forum.

  • Shailee Shah Profile Picture
    84 on at

    Thanks Martin, Will try your suggestion. Apart from this the reason behind this post is to understand if there are other approaches through which same requirement can be achieved. (i.e. Post Type: Discussion)

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > Supply chain | Supply Chain Management, Commerce

#1
Laurens vd Tang Profile Picture

Laurens vd Tang 271 Super User 2025 Season 2

#2
Siv Sagar Profile Picture

Siv Sagar 171 Super User 2025 Season 2

#3
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 130 Super User 2025 Season 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans