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

How to set defaul value on FormGrid from Header Tab

(0) ShareShare
ReportReport
Posted on by 18,306

Hello Experts,

Happy New Year!

I have two table : 1 WorkOrderHeaderTable  2. WorkOrderDetailsTable.

Used Detailed Transaction FormPattern to design.

On DetailGrid , I want to set primary field value (WorkOrderNo) when Add Button click. How to do? I tried used "initvalue" method on WorkOrderDetailsTable but no luck.

Any exmaple of code will be highly appreciated.


Thanks much
Sandip

I have the same question (0)
  • Verified answer
    WillWU Profile Picture
    22,361 on at

    Hi Sandip,

    You could copy the onclick eventhandler of that Add command button and write your own logic to set the value.

       [FormControlEventHandler(formControlStr(SalesEditLines, AddHeaderButton), FormControlEventType::Clicked)]
        public static void AddHeaderButton_OnClicked(FormControl sender, FormControlEventArgs e)
        {
            Args args = new Args();
            FormCommandButtonControl  callerButton = sender as FormCommandButtonControl;  //Retrieves the button that we're reacting to
            FormRun form = callerButton.formRun(); //Gets the running SalesEditLines form
    
            FormDataSource salesParmTable_ds = form.dataSource(formDataSourceStr(SalesEditLines, SalesParmTable)) as FormDataSource;
            SalesParmTable salesParmTable = salesParmTable_ds.cursor();
    
    
            SalesTable salesTable=salesParmTable.salesTable();
    
         
         
                //Any Action...
    
            
    
        }

  • Suggested answer
    sandipdjadhav Profile Picture
    18,306 on at

    Hello Will,

    Much appreciated for you reply. I did it with FormDataSource level InitValue. Below is code-

    [DataSource]

       class WorkDetailsTable

       {

           /// <summary>

           /// Next routine will bring default value on WorkOrderDetail Table WorkOrder#

           /// </summary>

           public void initValue()

           {

               super();

               WorkOrderTable wrkOrdHdrTbl =WorkOrderTable_ds.cursor();

               WorkDetailsTable.WorkOrderNo = wrkOrdHdrTbl.WorkOrderNo;

           }

       }

  • Verified answer
    Pete Alberts Profile Picture
    3,542 on at

    Hi Sandip

    Did you specify the "Join source" property on the WorkOrderDetailsTable DS?

    If you created a relation on the WorkOrderDetailsTable (FK WorkOrderDetailsTable.WorkOrderNo == WorkOrderHeaderTable.WorkOrderNo) and you set the mentioned property on the DS then you won't need to write any code.

    Your code is correct. Something is overring it, or WorkOrderTable.WorkOrderNo is blank. Debugging will shed some light on that. But I'd recommend you stay with relations and properties (it's counter productive to write code for something that is already automated by MS kernel).

  • sandipdjadhav Profile Picture
    18,306 on at

    Hello Pete,

    Much appreciated for your replied.  You are 100% correct. I have just tested solution and it works. No code is rquired.

    Thanks much
    Sandip

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 660 Most Valuable Professional

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 307 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans