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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

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

Custom Fields not accessible in form methods

(0) ShareShare
ReportReport
Posted on by 169

Dear Champions;

Hope all of you are doing good, i am new to D365 Development, I am creating extension of PurchParmtable and adding a new date Field.

Firstly i want to add validation on the field that's already done and working, Now i want to add one more condition on the same field but the issue is 

once i tried to access the field in my method, i am able to access all the default fields but my custom field is not accessible even i set the option

Auto declaration to yes.

Could Someone please let me know what's i am doing wrong and why i am not able to access the field..

Thanks and Best Regards.

  • Martin Dráb Profile Picture
    240,847 Most Valuable Professional on at

    Please tell us whether the table extension adding the field is in the same model as your class. If not, make sure that there is a reference between them.

    Do you get a compilation if you write the field name manually (instead of depending on IntelliSense)?

    Auto Declaration is used for form controls, not table fields, therefore it shouldn't be applicable to you at all - unless you forgot to tell us something. You should validate the value of the table field, not of a form control. Please show us your code.

  • Mohamed Ahmed Hassan Profile Picture
    169 on at

    Hi Martin;

    Thanks for your Reponses, Here is my code and I am also adding a screenshot for the table extension.

    [FormControlEventHandler(formControlStr(PurchEditLines, OK), FormControlEventType::Clicked)]
    public static void OK_OnClicked(FormControl sender, FormControlEventArgs e)
    {

    boolean ret;

    FormDataSource      fds = sender.formRun().dataSource("PurchParmTable");
    PurchParmTable      mypurchTable = fds.cursor();
    FormRun             fr = sender.formRun();
    FormControl         fc = fr.design(0).controlName("DeliveryDate");
    VendTable vendTable;
    Select vendTable where vendtable.accountnum == mypurchTable.OrderAccount;
    if(vendTable.vendGroup =='20' || vendTable.vendGroup =='10')
    {
    info(strFmt("%1", (fc.valueStr()==null)));
    if(fc.valueStr()==null)
    {
    //ret = checkFailed("Delivery Date must be filled in");
    warning(strFmt("Delivery Date must be filled in"));
    fds.refresh();
    fds.research(true);

    ret = false;
    }
    else
    {

    ret = true;
    }
    }

    85345.Capture.PNG

  • André Arnaud de Calavon Profile Picture
    307,271 Super User 2026 Season 2 on at

    Hi Mohamed,

    When you paste coding, can you use the rich formatting and choose: Insert > Code? In that way, it would be better to read it.

    [FormControlEventHandler(formControlStr(PurchEditLines, OK), FormControlEventType::Clicked)]
    public static void OK_OnClicked(FormControl sender, FormControlEventArgs e)
    {
    
        boolean ret;
    
        FormDataSource      fds = sender.formRun().dataSource("PurchParmTable");
        PurchParmTable      mypurchTable = fds.cursor();
        FormRun             fr = sender.formRun();
        FormControl         fc = fr.design(0).controlName("DeliveryDate");
        VendTable vendTable;
        Select vendTable where vendtable.accountnum == mypurchTable.OrderAccount;
        if(vendTable.vendGroup =='20' || vendTable.vendGroup =='10')
        {
            info(strFmt("%1", (fc.valueStr()==null)));
            if(fc.valueStr()==null)
            {
                //ret = checkFailed("Delivery Date must be filled in");
                warning(strFmt("Delivery Date must be filled in"));
                fds.refresh();
                fds.research(true);
    
                ret = false;
            }
            else
            {
    
                ret = true;
            }
        }
    }

    You shared your coding without further explaining your issue. Can you tell if you have build errors or what else might be not working? What is it exactly what you want to achieve?

  • Mohamed Ahmed Hassan Profile Picture
    169 on at

    Hi Andre;

    Sorry not to follow the code formatting, 

    if(fc.valueStr()==null)
            {
                //ret = checkFailed("Delivery Date must be filled in");
                warning(strFmt("Delivery Date must be filled in"));
                fds.refresh();
                fds.research(true);
    
                ret = false;
            }
            else
            {
    
                ret = true;
            }

    In the Else statement, what i want to do is if the date is inserted in the table(PurchParmTable) i want to write and update statement to update the same

    field i.e. Delivery Date in purchline Table.

    Now the issue is i want to access the field like mypurchTable.DeliveryDate but the field is not accessible in the mehtod.

    Thanks and Regards

  • Martin Dráb Profile Picture
    240,847 Most Valuable Professional on at

    The key problem of your code is that it's at a wrong place. But let's pretend that you're doing the right thing and let me show you how you would in that case.

    You said your tried to access the field, but your code never does that. What you tried instead to was getting a control called "DeliveryDate" by hard-coded names. (Please always use formControlStr() instead of a control name as text). That's a different thing than a table field.

    Let me rewrite your code to actually use your field.

    [FormControlEventHandler(formControlStr(PurchEditLines, OK), FormControlEventType::Clicked)]
    public static void OK_OnClicked(FormControl sender, FormControlEventArgs e)
    {
    	// This is not perfect, but let's improve it later
        FormDataSource fds = sender.formRun().dataSource("PurchParmTable");
        PurchParmTable myParmTable = fds.cursor();
    
    	// Check DeliveryDate first. Don't waste resources to call the query below
    	// if you don't need the result.
    	if (!myParmTable.DeliveryDate)
    	{
    		VendTable vendTable;
    	
    		select firstOnly RecId from vendTable
    			where vendTable.Accountnum == mypurchTable.OrderAccount
    			   && (vendTable.vendGroup == '20' || vendTable.vendGroup == '10');
    		
    		if (vendTable.RecId)
    		{
    			warning("Delivery Date must be filled in");
    		}
    	}
    }
    x

    Note that I removed 'ret' variable, because it's never read. The method doesn't return any value.

  • Martin Dráb Profile Picture
    240,847 Most Valuable Professional on at

    If you want to update a field on PurchLine from PurchParmLine, you're at a completely wrong place. This is a clicked method of a form, not the posting logic nor the logic copying data between those tables. You seem to forget that there is existing code that can help you and that you must respect.

    Please go to PurchLine table and check if there isn't a method initializing from PurchParmLine. If not, I can find the right method for you tomorrow.

  • Mohamed Ahmed Hassan Profile Picture
    169 on at

    Thanks Martin for your response, I am also checking and waiting for your response as well.

  • Martin Dráb Profile Picture
    240,847 Most Valuable Professional on at

    Can you explain your business scenario, please?

    It's strange that you want to update PurchLine from PurchParmLine. PurchParmLine table represents purch lines selected for posting, therefore you normally intialize PurchParmLine from PurchLine and not the other way around.

    Note that order lines can be updated on posting (e.g. the status may change the Invoiced), but that's not directly from PurchParmLine.

  • Mohamed Ahmed Hassan Profile Picture
    169 on at

    Hi Martin;

    Really sorry to bother you, There is one field in PO Line Details(Please see the attached image),  I want the users to select the delivery date during the time PO Receiving and want to update the PO Line Delivery Date Automatically. Also want to validate the field if the field is empty user will get a notification msg.

    1602.delivery-date.PNG

    Thanks

  • Verified answer
    Martin Dráb Profile Picture
    240,847 Most Valuable Professional on at

    Thank you for these details.

    The class posting product receipts is called PurchPackingSlipJournalPost. If you want to update PurchLine just before posting, updateSourceLineBeforePosting() looks like the right method.

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the August Top 10 Community Leaders

These are the community rock stars!

Leaderboard > Finance | Project Operations, Human Resources, AX, GP, SL

#1
Martin Dráb Profile Picture

Martin Dráb 523 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 408 Super User 2026 Season 2

#3
CU10121822-0 Profile Picture

CU10121822-0 354

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans