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 insert data to table on button click ?

(0) ShareShare
ReportReport
Posted on by 135

I have a form on which i place a simple button and on this button click i want to insert today date time with some text in table field.

6175.pastedimage1672350114858v1.png

I have written above code on button click override method but it is showing error, please can any one guide me ?

I have the same question (0)
  • Verified answer
    André Arnaud de Calavon Profile Picture
    301,035 Super User 2025 Season 2 on at

    Hi itlabnarmi,

    Can you tell what exact error message you get? Is the table in which you want to insert a record also a data source on the form?

    I do assume you already get a build error as the TableName object is not a table. It is a string variable. If Mytable is a datasource on the form, you can use the next coding:

    [Control("Button")]
    class AddReview
    {
        /// 
        /// This method will add a review in Mytable
        /// 
        public void clicked()
        {
            super();
           
            ttsbegin;
           
            Mytable.review = 'Review completed on '   date2Str(DateTimeUtil::getSystemDateTime());
            Mytable.insert();
           
            ttscommit;
        }
    }

    If the Mytable is not a datasource on the form, use the next coding where you declare the table variable.

    [Control("Button")]
    class AddReview
    {
        /// 
        /// This method will add a review in Mytable
        /// 
        public void clicked()
        {
            Mytable  mytable;
        
            super();
           
            ttsbegin;
           
            mytable.review = 'Review completed on '   date2Str(DateTimeUtil::getSystemDateTime());
            mytable.insert();
           
            ttscommit;
        }
    }

  • Suggested answer
    GirishS Profile Picture
    27,827 Moderator on at

    Hi itlabnarmi_ivoruk

    In addition to Andre comments, I guess error is due to date2str function.

    date2tr function expects date time value but you are passing date value.

    Make use of DateTimeUtil class to convert date to string like below.

    MyTable.review = "Review completed on"   DateTimeUtil::tostr(DateTimeUtil::getSystemDateTime());

    Thanks,

    Girish S.

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

#2
André Arnaud de Calavon Profile Picture

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

#3
Sohaib Cheema Profile Picture

Sohaib Cheema 254 User Group Leader

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans