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 :
Finance | Project Operations, Human Resources, ...
Answered

Extension of Delegate Handler Method

(0) ShareShare
ReportReport
Posted on by 77

Good afternoon,

I am looking to extend an existing method in order to add an additional field to the Job Registration screen. This method is Forms\JmgRegistration.mapPreviewFieldControlToFieldNameDelegateHandler().

The method that I am trying to extend is thus:

 /// 
    /// Delegate handler for mapping a preview field control to JmgFieldName enumerations.
    /// 
    /// The name of the control to map.
    /// A collection where the mapped enumerations can be returned
    [SubscribesTo(classStr(JmgRegistrationForm), delegateStr(JmgRegistrationForm, mapPreviewFieldControlToFieldNameDelegate))]
    public static void mapPreviewFieldControlToFieldNameDelegateHandler(FormControlName _controlName, Set _fieldNames)
    {
        switch (_controlName)
        {
            case formControlStr(JmgRegistration,preProd_prodOrder):
                _fieldNames.add(JmgFieldName::ProdOrder);
                break;
            case formControlStr(JmgRegistration,preProd_OprActId):
                _fieldNames.add(JmgFieldName::OperationActivity);
                break;

            etc etc...

        }

    }


I have tried to extend it like so:

[ExtensionOf(classstr(JmgRegistrationForm))]
final class JmgRegistrationFormTTN07720_Extension
{

    public static void mapPreviewFieldControlToFieldNameDelegateHandler(FormControlName _controlName, Set _fieldNames)
    {

        switch (_controlName)
        {
            case formControlStr(JmgRegistration,CuttingListId):
                _fieldNames.add(JmgFieldName::CuttingListId);
                break;
        }

        next mapPreviewFieldControlToFieldNameDelegateHandler(_controlName, _fieldNames);
    }

}

This extension is never called.

Please can someone advise me where I am going wrong?

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

    I would expect it to work (I don't know how you tested whether the method gets called), but I wouldn't use it anyway. Why don't you simply subscribe to the same delegate?

  • PhilMatthews Profile Picture
    77 on at

    Thanks for the response Martin. I'm testing whether it is called using debugging in VS using breakpoints in lines 8 and 11 in my code.

    I've now amended as per your suggestion to subscribe to the delegate like so:

    [ExtensionOf(classstr(JmgRegistrationForm))]
    final class JmgRegistrationFormTTN07720_Extension
    {
        [SubscribesTo(classStr(JmgRegistrationForm), delegateStr(JmgRegistrationForm, mapPreviewFieldControlToFieldNameDelegate))]
        public static void mapPreviewFieldControlToFieldNameDelegateHandlerTTN(FormControlName _controlName, Set _fieldNames)
        {
    
            switch (_controlName)
            {
                case formControlStr(JmgRegistration,CuttingListId):
                    _fieldNames.add(JmgFieldName::CuttingListId);
                    break;
            }
    
        }
    
    }

    It still doesn't get called though. I've verified this using debugging on my code and also some latter code which cycles through the content of the _fieldNames Set.

  • Verified answer
    Martin Dráb Profile Picture
    237,884 Most Valuable Professional on at

    Maybe you have a problem with debugging. What if you try to add a message to infolog? Like this:

    [ExtensionOf(classstr(JmgRegistrationForm))]
    final class JmgRegistrationFormTTN07720_Extension
    {
        [SubscribesTo(classStr(JmgRegistrationForm), delegateStr(JmgRegistrationForm, mapPreviewFieldControlToFieldNameDelegate))]
        public static void mapPreviewFieldControlToFieldNameDelegateHandlerTTN(FormControlName _controlName, Set _fieldNames)
        {
    		info("Handler is called!");
        }
    }

    If everything is compiled and deployed, and you execute code that calls the delegate, and no other delegate throws an exception, then this method must be called and you should see a message in infolog.

    Note that I instentionally don't look for a particular _controlName. If I did, I wouldn't be testing whether the method is called. It would be testing whether it's called for a particular control, which is a different question.

  • PhilMatthews Profile Picture
    77 on at

    Thank you for your help on this Martin, you are correct. Two issues in play here:

    1) The debugger was not being triggered. I am unsure why, so will troubleshoot that myself.

    2) I had added the field to the wrong grid setup.

    I will just slide away and pretend that this never happened. Thank you for your help.

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 > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 544 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 250 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans