Skip to main content

Notifications

Power Apps - Power Apps Pro Dev & ISV
Suggested answer

Creating an Object in a Table Based on Data Selected in a Form

Like (1) ShareShare
ReportReport
Posted on 3 Oct 2024 10:57:50 by 2
I want to create an object in a table on my PowerApps page using 3 Text Inputs that are connected to two different tables (Appareil and Activité). Additionally, there are two Date Inputs: the first one captures the Month and Year, while the second one captures the Day, Month, and Year. Based on the selected data from these inputs, the object will be created in the respective table.
  • Niranjanbabu Chakali Profile Picture
    Niranjanbabu Chakali 23 on 05 Oct 2024 at 03:37:02
    Creating an Object in a Table Based on Data Selected in a Form
    Hello,

    Here’s a formula for the OnSelect property of the submit button that handles the object creation logic:
     
    // Extract month and year from DatePicker1
    Set(SelectedMonth, Month(DatePicker1.SelectedDate));
    Set(SelectedYear, Year(DatePicker1.SelectedDate));
    // Extract day, month, and year from DatePicker2
    Set(SelectedDay, Day(DatePicker2.SelectedDate));
    Set(SelectedFullMonth, Month(DatePicker2.SelectedDate));
    Set(SelectedFullYear, Year(DatePicker2.SelectedDate));
    // Create object in the Appareil table
    Patch(
        Appareil,
        Defaults(Appareil),
        {
            AppareilName: TextInput1.Text,
            Description: TextInput3.Text,
            MonthYear: DateValue(SelectedMonth & "/01/" & SelectedYear)  // Example format for Month and Year
        }
    );
    // Create object in the Activité table
    Patch(
        Activité,
        Defaults(Activité),
        {
            ActivitéName: TextInput2.Text,
            EventDate: DateValue(SelectedFullMonth & "/" & SelectedDay & "/" & SelectedFullYear)  // Example format for full date
        }
    );
     
  • Suggested answer
    Nandit Profile Picture
    Nandit 1,545 on 05 Oct 2024 at 02:20:43
    Creating an Object in a Table Based on Data Selected in a Form
     
    When you say you want to create an object, do you mean creating a new record in your Data Source?
    If yes, you can use the following code (modify it based on your control names) and it should create a record -
    ​
    Patch(DataSource,
          Defaults(DataSource), {
          DateColumn: DateControl.SelectedDate
    TextColumn: TextInput.Value
    .
    .
    .
    and so on
    })
    
    ​
    Hope this helps. 
     
    Kind regards, 
    Nandit
     
    If this answers your query, please mark this response as the answer.
    If its helpful, please leave a like. Thanks!
     
     
     

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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #9 Get Recognized…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 144,411

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 64,328

Leaderboard
Loading complete