Skip to main content

Notifications

Announcements

No record found.

Finance | Project Operations, Human Resources, ...
Suggested answer

how can i passing formdatasource to a class?

(0) ShareShare
ReportReport
Posted on by

hi all!
how can I pass a form DataSource to a class because it gives me an error of the tablename_ds is not declared?

[FormControlEventHandler(formControlStr(RetailTransactionTable, RetailReport_Transaction), FormControlEventType::Clicked)]
    public static void RetailReport_Transaction_OnClicked(FormControl sender, FormControlEventArgs e)
    {
        MultiSelectionHelper                    selectionHelper = MultiSelectionHelper::construct();
         
        RetailTransactionTable                  retailTransactionTable;
       
        str                                     transId;
            
      
        selectionHelper.parmDataSource(TableName_ds);
        retailTransactionTable1  = selectionHelper.getFirst();

        transId = retailTransactionTable.transactionId;
        }

  • GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: how can i passing formdatasource to a class?

    Have you debugged the code?

    Find out in which line the error is throwing.

    Thanks,

    Girish S.

  • RE: how can i passing formdatasource to a class?

    hi when i try your line i recieved this error when trying to run the form

  • Suggested answer
    GirishS Profile Picture
    GirishS 27,821 Super User 2024 Season 1 on at
    RE: how can i passing formdatasource to a class?

    If you are writing COC then you can use directly the variables and DataSource names - If you are using event handlers you need to get form run and then get the datasource from form run.

    [FormControlEventHandler(formControlStr(RetailTransactionTable, RetailReport_Transaction), FormControlEventType::Clicked)]
        public static void RetailReport_Transaction_OnClicked(FormControl sender, FormControlEventArgs e)
        {
            MultiSelectionHelper                    selectionHelper = MultiSelectionHelper::construct();
             
            RetailTransactionTable                  retailTransactionTable;
           
            str                                     transId;
                
            //get the form run
            FormRun frun = sender.formRun();
            FormDataSource fds = frun.datasource(formDataSourceStr(FormName,DataSourceName));
            selectionHelper.parmDataSource(fds);
            retailTransactionTable1  = selectionHelper.getFirst();
            if(retailTransactionTable1)
            {
                //do some process
                transId = retailTransactionTable.transactionId;
                retailTransactionTable1 = selectionHelper.getNext()
            }
                
            }

    Thanks,

    Girish S.

  • Suggested answer
    Mohit Rampal Profile Picture
    Mohit Rampal 12,554 Super User 2024 Season 1 on at
    RE: how can i passing formdatasource to a class?

    Hi, You need to initialize FormDatasource buffer. Try adding below code at Line#9

    FormDatasource TableName_ds = sender.formrun().datasource(IdentifierStr(Tablename));

    Replace TableName with name of Datasource name.

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

Announcing Our 2025 Season 1 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Vahid Ghafarpour – Community Spotlight

We are excited to recognize Vahid Ghafarpour as our February 2025 Community…

Congratulations to the January Top 10 leaders!

Check out the January community rock stars...

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 292,162 Super User 2025 Season 1

#2
Martin Dráb Profile Picture

Martin Dráb 230,962 Most Valuable Professional

#3
nmaenpaa Profile Picture

nmaenpaa 101,156

Leaderboard

Product updates

Dynamics 365 release plans