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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Populate NewForm() wit...
Power Apps
Unanswered

Populate NewForm() with Data from Variables

(0) ShareShare
ReportReport
Posted on by 2

Hello, I'm developing a simple App that allows for Purchase Requisitions. 

The data consists of 2 tables. One is a header table, one is a details table.

I'm using SharePoint Lists as the data connection.

In order to keep the data in the Detail linked to the header I'm using a request ID.

I'm also using a combination if RequestID and LineItem together to create a unique row.

I'm trying to create a NewForm() and pre-populate it with the RequestID and LineItemID.

I'm able to set these values in a Variable using Collect() from the selected Detail table. I use the Request ID and then I look for the largest LineItemID and add 1.

I'm can not figure out how to add the Variable data to the newform.

I tried changing the Default Value, but when I do that it decouples it from the DataSource List.

 

 

NewForm(Detail_Edit);
Collect(
DetailRecord,
DataTable1.Selected
);
Set(
DetailRequestID,
DataTable1.Selected.RequestID
);
Set(
DetailLineNum,
LookUp(
SortByColumns(
Filter(
'B&G_Req_Detail',
NewReqID = RecordSelected
),
"field_1",
Descending
),
NewReqID = RecordSelected,
LineItemNum
)
);
Set(
DetailNextLineNum,
DetailLineNum + 1
);

 

From here I was hoping it would be as simple as something like....

Detail_Edit.LineNum.value = DetailNextLineNum

or Set(Detail_Edit.LineNum.value = DetailNextLineNum)

or something similar.

 

Any help would be appreciated.

 

 

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,297 Super User 2024 Season 1 on at

    @HiltonJE 

    You cannot set a value of a control in PowerApps.  PowerApps is modeled after Excel, so, just like in Excel you would not (from one cell) set another cell with something like B2="text", you would not do this in PowerApps either.  Just like cells in Excel, you use Formulas on the properties of the controls to set them.  So you would need to alter the appropriate property and provide a formula to reference the variable.

     

    However, this is overcomplicated (your scenario) for PowerApps.  It is much easier to do what you want.

     

    First, you don't even need to create your own unique ID's.  Your SharePoint list already has one...the ID column.  Use that to connect your parent and child records.

    The same applies to the child list...it has a Unique ID as well.  So, trying to create your own is just extra work.

     

    Now, the next piece of this is how are you doing your design?  It was not entirely clear from your description.

    Ideally, you would have a form that would deal with your parent (header) and then a gallery for your line items.  You seem to indicate that perhaps you have a form for your line items?  

    Not sure entirely where you are with that part.

    If you could expand on it a little (perhaps even a screenshot), that would be helpful.

     

  • HiltonJE Profile Picture
    2 on at

    Randy, thank you for the guidance.  Hopefully below I'm offering enough information, without being to verbose.

    100% transparency, I am NOT a programmer. I am a network admin that is a script kiddie to get where I need to be and get myself into trouble.

     

    My current "design" is a BrowseGallery with the HeaderTable Source.

    HiltonJE_0-1665669133684.png

     

    When you click a record there it brings you to a DetailScreen with the HeaderTable Source. Also, when you click the Browsescreen record, it sets a RequestID Variable.

    Navigate(DetailScreen1, ScreenTransition.None);
    Collect(SelectedRecord,BrowseGallery1.Selected);
    Set(RecordSelected,BrowseGallery1.Selected.RequestID)

    HiltonJE_1-1665669207336.png

    From here you can Edit the Header record (this will eventually be home to workflow processing as well for approvals)

    You can also click the Line Detail button which opens a Line Detail screen with a new datasource Req_Detail that contains line items of parts for order.

    This page has two controls on it. A view table and a form.

    When you click a record in the Table it open the form for editing of that record.

    The table opens using the Variable set before at the header screen.

    SortByColumns(Filter('B&G_Req_Detail',NewReqID=RecordSelected),"field_1",Ascending)

    HiltonJE_2-1665669452499.png

    Form Data is set with:

    HiltonJE_3-1665669606975.png

     

    When you click the New record button it calls the NewForm() function. I also create some Variables that were intended to set the Next Line number and requestID number, this was how I planned to tie the Header and Detail information together.
    I also intended to add things like username, Now() and other default values to the Form.

     

    HiltonJE_4-1665669779410.png

     

    NewForm(Detail_Edit);
    Collect(
    DetailRecord,
    DataTable1.Selected
    );
    Set(
    DetailRequestID,
    DataTable1.Selected.RequestID
    );
    Set(
    DetailLineNum,
    LookUp(
    SortByColumns(
    Filter(
    'B&G_Req_Detail',
    NewReqID = RecordSelected
    ),
    "field_1",
    Descending
    ),
    NewReqID = RecordSelected,
    LineItemNum
    )
    );
    Set(
    DetailNextLineNum,
    DetailLineNum + 1
    );

     

     

    Cancel button just calls the ResetForm() function.

    Erase calls the Remove('B&G_Req_Detail',DataTable1.Selected) function.

    Save calls the SubmitForm() function.

     

    I'm having a hard time figuring out how I would link the header and detail data together without some sort of a key (unique id per Instance of Header, to detail.

     

    Attached is the sample data I'm using.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 721 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 320 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard