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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Finance | Project Operations, Human Resources, ...
Answered

How to add switch case in form PSAVendorPaymentRetentionRelease DS init method using event handler in D365FO

(0) ShareShare
ReportReport
Posted on by 632

Hello friends,

In form PSAVendorPaymentRetentionRelease -> PSATmpVendInvoiceTable DS -> Init Method

I want to add  one more switch case condition for adding my customized form name.

75866.Capture.PNG

Please tell me how i can do it by using event handler in D365FO.

Thanks & Regards

Rahul

I have the same question (0)
  • Rahul.p Profile Picture
    632 on at

    Thank you Martin, it's working.

  • Verified answer
    Martin Dráb Profile Picture
    238,286 Most Valuable Professional on at

    My mistake - I forgot we're in a data source extension and not a form extension.

    Initialize projIdValue by this code:

    FormStringControl projIdValue = element.ProjIdValue;

    It could also be done this way:

    FormStringControl projIdValue = element.control(element.controlId(formControlStr(PSAVendorPaymentRetentionRelease, ProjIdValue)));

  • Rahul.p Profile Picture
    632 on at

    [ExtensionOf(FormDatasourceStr(PSAVendorPaymentRetentionRelease,PSATmpVendInvoiceTable))]
    final class PSAVendorPaymentRetentionRelease_Extension
    {
        public void init()
        {
            ProjTable projTable;        
    
            next init();
    
            if (element.args().caller())
            {
                switch (element.args().caller().name())
                {
                    case formStr (CON_Order):
                        projTable = element.args().record();
                        element.projId(projTable.ProjId);    
                        ProjIdValue.text(projTable.ProjId);                   
                        break;
                }
            }
        }
    
    }

  • Martin Dráb Profile Picture
    238,286 Most Valuable Professional on at

    Can you show us your full code, please?

  • Rahul.p Profile Picture
    632 on at

    Dear Martin,

    Thank you for your reply.

    At line no 12

    ProjIdValue.text(projTable.ProjId);

    I am getting 'Variable 'ProjIdValue' is not found in scope.'error.

    Please tell me how to solve this.

  • Verified answer
    Martin Dráb Profile Picture
    238,286 Most Valuable Professional on at

    This is not possible - you'll have to look for another solution.

    Fortunately, it's very easy:

    public void init()
    {
    	next init();
    	
    	if (element.args().caller())
    	{
    		switch (element.args().caller())
    		{
    			case formStr(YourForm):
    				projTable = element.args().record();
    				element.projId(projTable.ProjId);
    				ProjIdValue.text(projTable.ProjId);
    				break;
    		}
    	}
    }

    Yes, you'll have to duplicate a few lines of code, which is not ideal but it's the best option you have.

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

News and Announcements

Season of Giving Solutions is Here!

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
Abhilash Warrier Profile Picture

Abhilash Warrier 843 Super User 2025 Season 2

#2
André Arnaud de Calavon Profile Picture

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

#3
Martin Dráb Profile Picture

Martin Dráb 322 Most Valuable Professional

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans