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 / Code that patches a va...
Power Apps
Answered

Code that patches a variable breaks a screen

(0) ShareShare
ReportReport
Posted on by 260

Hello

 

I have an edit form that I have a text box for the weather on

 

The idea is that the user presses the weather icon and the app will get the current weather and update the box

 

I am doing this using


Set(varLocation, Text(Location.Latitude)&","&Text(Location.Longitude));
UpdateContext({Weather: MSNWeather.CurrentWeather(varLocation, "Metric")});
Set(varCurrentDiaryEntry, Patch(varCurrentDiaryEntry, {Field_2: Weather.responses.weather.current.cap}));

This code is only invoked when the icon is clicked, but as soon as this exists, my screen no longer works

 

There are no errors

 

What is the problem?

 

I have also tried this on a button outside of the edit form

 

Paul

Categories:
I have the same question (0)
  • Verified answer
    WarrenBelz Profile Picture
    156,100 Most Valuable Professional on at

    Hi @paulinuk ,

    Firstly, if you are trying to set a Variable, you should be able to do this

    With(
     {
     wWeather: 
     MSNWeather.CurrentWeather(
     Location.Latitude & "," & Location.Longitude,
     "Metric"
     )
     },
     Set(
     varCurrentDiaryEntry,
     {Field_2: wWeather.responses.weather.current.cap}
     )
    );
    

    Your output would then be

    varCurrentDiaryEntry.Field_2

    and simply sets a Variable. What happens to your screen?

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

     

  • paulinuk Profile Picture
    260 on at

    Thanks 

     

    Yes this is what I am trying to do but as soon as I put this code into an icon inside or a button outside the form the screen doesnt work at all

     

    I have also seen the message below which could be related but I have no idea how to resolve

    paulinuk_0-1642301511569.png

     

  • WarrenBelz Profile Picture
    156,100 Most Valuable Professional on at

    Hi @paulinuk ,

    What has the Item of the Form got to do with this? What is the code on there?

  • paulinuk Profile Picture
    260 on at

    This error happens when I put the code you showed above in a button outside of the form

     

    Im wondering if the designer is trying to evaluate this code at design time when the variable is nul?

  • WarrenBelz Profile Picture
    156,100 Most Valuable Professional on at

    @paulinuk ,

    The error you have posted refers to the Item of the Form - what is the code there?

    I have also tested the code I posted (I also use this function) and it is valid whether inside or outside a form as it does not refer to anything in the form.

  • paulinuk Profile Picture
    260 on at

    I have changed this to be the best practice and the error has gone again, it seems to come up every now and then

     

    My current code for the Item of form is 

     

    LookUp('Site Diary Entries',ID=varCurrentDiaryEntryId)

     

    The problem now is that I cant use your logic as that updates a variable, which is now not being used as the Item for this form due to this error?

  • WarrenBelz Profile Picture
    156,100 Most Valuable Professional on at

    Hi @paulinuk ,

    But the Variable you are setting on the weather is varCurrentDiaryEntry which is actually a Table with Field2 containing the weather. The Variable in your Form Item is CurrentDiaryEntryId - how is that stopping you using the weather code?

     

  • paulinuk Profile Picture
    260 on at

    Because I thought I had to update the exact variable that the form is bound to.

     

    The weather code is working fine now

     

    When the user clicks on a weather button on the edit form I want to change the value of the Weather text box to be the weather returned from MSN

     

    paulinuk_0-1642336912392.png

     

  • paulinuk Profile Picture
    260 on at

    I’ve tried loads of different ways but nothing updates the text box on my form do I need to do something to force the box to refresh?

  • WarrenBelz Profile Picture
    156,100 Most Valuable Professional on at

    Hi @paulinuk ,

    Make the Default of the Text box (not the data card)

    varCurrentDiaryEntry.Field_2

     

    Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

    Visit my blog Practical Power Apps

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 June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 325 Most Valuable Professional

#2
11manish Profile Picture

11manish 165

#3
MS.Ragavendar Profile Picture

MS.Ragavendar 88 Super User 2026 Season 1

Last 30 days Overall leaderboard