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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Conditional UpdateCont...
Power Apps
Answered

Conditional UpdateContext for Text Input Item in Gallery

(0) ShareShare
ReportReport
Posted on by 19

I am trying to do the UpdateContext only in one Gallery Item and them Patch to a sharepoint list, like bellow.

 

UpdateContext({restrict: Value(TextInput1.Text)});;
If(restrict>ThisItem.Extra_Forecast; UpdateContext({restrict:ThisItem.Extra_Forecast}));;
Patch(App_ExtraForecast; ThisItem;{Equalization_Seller:Value(TextInput1.Text)})

 

The Patch is working fine, but when I put the UpdateContext and If condition, also as the restrict in the Default function, when I change an Text Input, it changes in all gallery item.

How can I do this UpdateContext only in the selected item of the gallery? 

 

Capturar.JPG

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

    @raphaqcl 

    Context variables are in the Context of the Screen, not the Gallery.  So, if you update a context variable in your gallery, it will apply to all.

     

    It appears that your goal of the formula is to patch the record if the TextInput is greater than the forecast value and then have the forecast value shown in the text input.

     

    Is that what you are trying to achieve or am I misunderstanding?

  • raphaqcl Profile Picture
    19 on at

    Hm, thanks, now I understoood the UpdateContext concept.

     

    My goal is that the user can't input a value in Volume Released that is greater than the value in Volume Requested.

  • raphaqcl Profile Picture
    19 on at

    To become more clearer, I was using in the TextInput1 of the Gallery this:

     

    On Change

     

    UpdateContext({restrict: Value(TextInput1.Text)});;
    If(restrict>ThisItem.Extra_Forecast; UpdateContext({restrict:ThisItem.Extra_Forecast}));;
    Patch(App_ExtraForecast; ThisItem;{Equalization_Seller:Value(TextInput1.Text)})

     

    Default

     

    restrict

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @raphaqcl 

    Yeah, sort of gathered that from the formula.  What I am NOT understanding from your formula is what you are using restrict for?  First you set it to the value of the text that was input, then you compare it and if larger, you then reset it to the forecast value.  What is the purpose of that then?  You don't seem to use it in the rest of the formula...where is it used?

  • raphaqcl Profile Picture
    19 on at

    @RandyHayes 

     

    Yes, I put it because if the user input some value larger than the ThisItem.Extra_Forecast (Volume Requested), then the TextInput automatically return to the Maximum value that is possible on the TextInput.

     

    But it is not extremelly necessary, if you know a way to just not allow to input an value larger than the  the ThisItem.Extra_Forecast will help a lot. 😃

  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @raphaqcl 

    Okay...making more sense now. Thanks!

     

    So then this is a consideration:

    1) add a label in the Gallery around the text input that and error message about the value entered being above allowed.  Set the Visible property to:  Value(TextInput1.Text) >ThisItem.Extra_Forecast

     

    2) On the OnChange, set the formula to:

    If(Value(TextInput1.Text) <= ThisItem.Extra_Forecast; 
     UpdateIf(App_ExtraForecast; ThisItem.ID;{Equalization_Seller: Value(TextInput1.Text)}
    )
    
    

     

    This will keep an invalid value from being updated back to the data source and it will give the user a visual notification that they have an error.

  • raphaqcl Profile Picture
    19 on at

    Thank you so much! @RandyHayes 

     

    The UpdateIf didn't work, but I change it for Patch, put the message too and worked perfect.

     

    If(Value(TextInput1.Text) <= ThisItem.Extra_Forecast;
    Patch(App_ExtraForecast; ThisItem;{Equalization_Seller:Value(TextInput1.Text)}))

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @raphaqcl 

    I'd investigate why the UpdateIf didn't work.  You'll have better success to lean on the UpdateIf over the Patch in most cases.  (think "patch" for new records and UpdateIf for existing records)  They will work pretty much the same, but there are some quirks with Patch that UpdateIf overcomes.

     

    Actually, I investigated for you 😁 I made a typo in the formula.  It should have been:

    If(Value(TextInput1.Text) <= ThisItem.Extra_Forecast; 
     UpdateIf(App_ExtraForecast; ID=ThisItem.ID;{Equalization_Seller: Value(TextInput1.Text)}
    )

    Forgot the ID....

     

     

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 416 Most Valuable Professional

#2
11manish Profile Picture

11manish 205 Super User 2026 Season 2

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 128 Super User 2026 Season 2

Last 30 days Overall leaderboard