1
votes

I have a PowerApp for which I am trying to build offline capabilities.Below is a scenario which I am trying to achieve.Need suggestions.

I have timer API method which basically executes when I start and stop a timer method in the app. In ONLINE mode it works fine, but I want to allow users to start/stop a timer in OFFLINE mode as well. When the app is in offline mode, the API call fails as it is not connected . how do i bypass that situation and start and stop a timer in offline mode . Is there a way to achieve that ? Here is my API definition.

ClearCollect(colTimers, Time360.timerStartStop({_timerContract:{
    Comment:txtDBTimerDescription.Text, 
    Running:"Yes", 
    IsPinned:"No", 
    CustomerAccount:tsLineCust.CustNum,
    ProjectId:tsLineProj.ProjectId,
    ProjectCategoryId:tsLineCat.CategoryId,
    ParentId:0,
    RecordId:0,
    ProjectDataAreaId:If(Len(tsLineCust.DataAreaId) > 0, tsLineCust.DataAreaId, If(Len(tsLineProj.DataAreaId) > 0, tsLineProj.DataAreaId))
    }}));
2
Does that timer API require internet ? - Shreamy
Yes it requires internet connection. - Partha Buragohain
Any help ? Kindly suggest - Partha Buragohain

2 Answers

1
votes

Use the Connection.Connected to see if you have an internet connection.

If(Connection.Connected, 
      // TRUE: connect to the api, 
      // FALSE: add to local collection
   )
0
votes

PowerApps has a Timer control built in.

  • Insert
  • Input/Timer

enter image description here

  • Set its Duration property to desired milliseconds
  • Set its Repeat to true to keep a pulse
  • Set its AutoStart to true to make it start when the screen loads
  • Set its OnTimerEnd to perform the function you desire (like the code below)

You may want to investigate the PowerApps SaveData() function.

Something like:

If(
    Connection.Connected,
        Patch(theDataSource,
        Defaults(theDataSource),
        {
            Comment:txtDBTimerDescription.Text, 
            Running:"Yes", 
            IsPinned:"No", 
            CustomerAccount:tsLineCust.CustNum,
            ProjectId:tsLineProj.ProjectId,
            ProjectCategoryId:tsLineCat.CategoryId,
            ParentId:0,
            RecordId:0,
            ProjectDataAreaId:If(Len(tsLineCust.DataAreaId) > 0, tsLineCust.DataAreaId, If(Len(tsLineProj.DataAreaId) > 0, tsLineProj.DataAreaId))
        }
    ),

    Collect(colLocalData, {...same stuff as above...});
    SaveData(fileLocalCache, colLocalData)
)

Paul O'Flaherty has one of the better PowerApps offline vids here.