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 / Use a toggle Switch to...
Power Apps
Unanswered

Use a toggle Switch to set an input field to now()

(1) ShareShare
ReportReport
Posted on by 40

I have found a couple different posts here that are close and I have tried them. 

 

I have a toggle switch that when turned on I want it to set the value in a text input field to the current date and time. I can get this to work using 

Patch('RoadSide Event Manager', First(Filter('RoadSide Event Manager', 'Work Order Number'= WOVar)),{On_Scene_Time: Now()});

I am experiencing odd behavior. The toggle is then switched on for every field to automatically be yes, and it updates the time to now every time the form is opened. 

 

The form is opened from a gallery and I need it to pull accurate information from the sharepoint list datasource. So if the value is set to no in the sharepoint list I need it to remain at no until the user sets it to yes. When the user sets it to yes then update On_Scene_Time to the date and time it happens. The tricky part from here is to keep the same value that is in sharepoint first. Then if its already a yes on the toggle leave the value in On_Scene_Time what it was. 

 

Steps needed. 

Toggle switch by default on all new records is No. 

User reports the activity completed by changing toggle to yes

Once it is marked yes update text input field named On_Scene_Time to date and time now()

Disable toggle so it cannot be changed from yes. 

Disable On_Scene_Time so it cannot be edited. 

 

The data source is a sharepoint list and the columns used are Yes/No and Single Line of Text. 

 

Thanks for the help. 

Categories:
I have the same question (0)
  • WarrenBelz Profile Picture
    155,962 Most Valuable Professional on at

    Hi @xbommer07 ,

    Can you please send a screen shot of your gallery - I assume that this toggle is in your gallery and the Patch code is being run on the OnChange of this control? Also does the toggle have a Default value?

  • xbommer07 Profile Picture
    40 on at

    Hello again @WarrenBelz 

     

    The toggle sits inside an edit form, and the default is parent.default. I am using oncheck with code, Patch('RoadSide Event Manager', First(Filter('RoadSide Event Manager', 'Work Order Number'= WOVar)),{On_Scene_Time: Now()}); 

     

     

    Form Toggle.jpg
  • WarrenBelz Profile Picture
    155,962 Most Valuable Professional on at

    Hi @xbommer07 ,

    Before we look at anything else, take the code off the OnCheck and put this on the OnChange (I assume 'Work Order Number' is a unique value) - replace with your control name

    If(
     YourToggleName.Value=true,
     UpdateIf(
     'RoadSide Event Manager', 
     'Work Order Number'= WOVar,
     {On_Scene_Time: Now()}
     )
    );
    Refresh(YourDataSourceName)

     

    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.

     

  • xbommer07 Profile Picture
    40 on at

    @WarrenBelz 

     

    New code is in place. Something is resetting the switch back to no(false). I have no code anywhere else on this control except the onchange. 

     

     

    If(
     Sw_OnScene.Value=true,
     UpdateIf(
     'RoadSide Event Manager', 
     'Work Order Number'= WOVar,
     {On_Scene_Time: Now()}
     )
    );
    Refresh('RoadSide Event Manager')

     

     

    I see the time get updated in On_Scene_Time then the switch sets itself back to false. Do you think I also need to add the toggle in to the update? Since the default is parent.default we refresh without a submit. 

  • WarrenBelz Profile Picture
    155,962 Most Valuable Professional on at

    Thanks @xbommer07 ,

    I was fearing that - OnChange is a better spot for it anyway, but firstly have a read of this post which is currently ongoing and appears to be the same issue as you are facing.

    Another thing you could try is to take the update off the toggle and put it on a "Submit" button in the gallery and see if that does the job.

     

    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.

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

#2
11manish Profile Picture

11manish 212

#3
Valantis Profile Picture

Valantis 167

Last 30 days Overall leaderboard