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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Dynamics 365 Community / Forums / Finance forum / How to add methods to ...
Finance forum

How to add methods to newly added custom controls in an extended form.

(0) ShareShare
ReportReport
Posted on by

I have added a new custom control namely MyContactpersonid2 in extended salescreateorder form, i want to add jumpref & lookup method from editcontactpersonname control to my newly created controls.

I have followed this community.dynamics.com/.../code-behind-extension-forms-how-to-add-state-variable-and-override-methods-without-overlayering

Code

[ExtensionOf(formStr(SalesCreateOrder))]
final class MySalesCreateOrder_Extension
{

    [FormEventHandler( formstr( Salescreateorder ) FormEventType::Initialized)]
    public void initializedFormHandler(xFormRun formRun, FormEventArgs e)
    {
        FormDataObject field1DataObject = this.SalesTable_ds.object( fieldNum(SalesTable, MyContactPersonId2), 1);

        MyContactPersonId2DataObject.registerOverrideMethod( methodStr(FormDataObject, jumpRef), formMethodStr( [ExtensionOf(formStr(SalesCreateOrder))]
       , jumpRefImplementation), this);

        FormDataObject field1DataObject = this.SalesTable_ds.object( fieldNum(SalesTable, MyContactPersonId2), 1);

        MyContactPersonId2DataObject.registerOverrideMethod( methodStr(FormDataObject, lookup), formMethodStr( [ExtensionOf(formStr(SalesCreateOrder))]
       , lookupImplementation), this);

        
    }

    public void jumpRefImplementation(FormDataObject MyContactPersonId2)
    {
        // My implementation of the override logic
    }


         public void lookupImeplementation(FormDataObject MyContactPersonId2)
         {
             //My  implementation of the override logic
         }

Error

Getting error at
    [FormEventHandler( formstr( Salescreateorder ) FormEventType::Initialized)]    // It keeps erroring  ) expected at FormEventType
    public void initializedFormHandler(xFormRun formRun, FormEventArgs e)
VSError

vserro.png

Please suggest what should i do to achive my objective which is to have  jumpref & lookup of editcontactperson to mycontactpersonid2

I have the same question (0)
  • Sukrut Parab Profile Picture
    71,741 Moderator on at

    Approach is fine . From you above code looks like you are missing closing bracket for class. Put that and try to build again

  • Mav Profile Picture
    on at

    ?

    That is exactly my problem all the brackets are closed yet this  ) expected error, can you let me know where do you think i should be putting extra bracket

  • Sukrut Parab Profile Picture
    71,741 Moderator on at

    Above code is the all code present in your class ? If not can u paste complete code of your class

  • Mav Profile Picture
    on at

    [ExtensionOf(formStr(SalesCreateOrder))]

    final class MySalesCreateOrder_Extension

    {

       [FormEventHandler( formstr( Salescreateorder ) FormEventType::Initialized)]

       public void initializedFormHandler(xFormRun formRun, FormEventArgs e)

       {

           FormDataObject field1DataObject = this.SalesTable_ds.object( fieldNum(SalesTable, MyContactPersonId2), 1);

           MyContactPersonId2DataObject.registerOverrideMethod( methodStr(FormDataObject, jumpRef), formMethodStr( [ExtensionOf(formStr(SalesCreateOrder))]

          , jumpRefImplementation), this);

           FormDataObject field1DataObject = this.SalesTable_ds.object( fieldNum(SalesTable, MyContactPersonId2), 1);

           MyContactPersonId2DataObject.registerOverrideMethod( methodStr(FormDataObject, lookup), formMethodStr( [ExtensionOf(formStr(SalesCreateOrder))]

          , lookupImplementation), this);

       }

       public void jumpRefImplementation(FormDataObject MyContactPersonId2)

       {

           // My implementation of the override logic

       }

            public void lookupImeplementation(FormDataObject MyContactPersonId2)

            {

                //My  implementation of the override logic

            }

    }                                                               //   Closing } of my extension class  was already there in my code somehow missed to share it earlier.

                                                            // All brackets are closed yet getting  ") expected" error at FormEventType:Initiallized)]

  • Mav Profile Picture
    on at

    @Sukrut  : Any further suggestions.

  • Sukrut Parab Profile Picture
    71,741 Moderator on at

    doesn't look anything wrong to me . Try to copy and paste event handler in another class and build it first just to see you get same error

  • Mav Profile Picture
    on at

    Tried in different class , :-( Same error ,   ") expected" error at FormEventType:Initiallized)]

    Can you try the code in ur system please.

  • Sukrut Parab Profile Picture
    71,741 Moderator on at

    Just notice that you are implementing event handler which is does not necessarily  be in the extension class . You can just implement in normal class Like SalesCreateOrderFormEventHandler . Here is good explanation about that

    daxmusings.codecrib.com/.../accidental-code-extensions.html\

    I tried in my environment and I did not get any error. See below definition which I copied.

    class TestEventHandler

    {

       [FormEventHandler(formStr(SalesCreateOrder), FormEventType::Initialized)]

       public static void SalesCreateOrder_OnInitialized(xFormRun sender, FormEventArgs e)

       {

       }

    }

  • Mav Profile Picture
    on at

    I think there was some issue in code, I got it fixed but now getting the following error when i click to see lookup.
    Pls suggest how to resolve this Unable to Cast Formstring control to FormDataObject.

    All I am trying to achieve is to have a similar lookup like we have for editcontactperson for my contact person

    .

    editcontactpersonerror.png

    Revised code

    [ExtensionOf(formStr(SalesCreateOrder))]
    final class ETSalesCreateOrder_Extension
    {
        [FormEventHandler( formstr( Salescreateorder ), FormEventType::Initialized)]
    
        public void initializedFormHandler(xFormRun formRun, FormEventArgs e)
        {
            FormDataObject MYContactPersonIdDataObject = this.SalesTable_ds.object( fieldNum(SalesTable, MYContactPersonId), 1);
    
            MYContactPersonIdDataObject.registerOverrideMethod( methodStr(FormDataObject, jumpRef), formMethodStr(SalesCreateOrder,jumpRefImplementation),this);
    
           FormDataObject MYContactPersonId1DataObject = this.SalesTable_ds.object( fieldNum(SalesTable, MYContactPersonId), 1);
    
            MYContactPersonIdDataObject.registerOverrideMethod( methodStr(FormDataObject, lookup), formMethodStr(SalesCreateOrder,lookupImeplementation),this);
    
    
        }
    
        public void jumpRefImplementation(FormDataObject MYContactPersonId)
        {
            // My implementation of the override logic
            salesTable_ContactPersonId2.jumpRef();
        }
    
             public void lookupImeplementation(FormDataObject MYContactPersonId)
             {
                 SalesTable lsalestable;
    
                 //My  implementation of the override logic
                ContactPerson::lookupCustContactPerson(salesTable_contactPersonId2,lsalestable.CustAccount,editContactPersonName2,lsalestable.MYContactPersonId);
    
              }
    		
    }
  • Sukrut Parab Profile Picture
    71,741 Moderator on at

    use formStringCOntrol  because  MYContactPersonId is a string control and then call register override method for that.

    FOrmStringControl MYContactPersonIdDataObject = this.SalesTable_ds.object( fieldNum(SalesTable, MYContactPersonId), 1);

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

November Spotlight Star - Khushbu Rajvi

Congratulations to a top community star!

Forum Structure Changes Coming on 11/8!

In our never-ending quest to help the Dynamics 365 Community members get answers faster …

Dynamics 365 Community Platform update – Oct 28

Welcome to the next edition of the Community Platform Update. This is a status …

Leaderboard > Finance

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans